mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-27 12:25:55 +03:00
caddyhttp: Improve docs, and Caddyfile for respond directive
This commit is contained in:
parent
85ff0e3604
commit
793a405810
2 changed files with 23 additions and 8 deletions
|
@ -35,7 +35,7 @@ import (
|
||||||
type (
|
type (
|
||||||
// MatchHost matches requests by the Host value (case-insensitive).
|
// MatchHost matches requests by the Host value (case-insensitive).
|
||||||
//
|
//
|
||||||
// When used in an HTTP route,
|
// When used in a top-level HTTP route,
|
||||||
// [qualifying domain names](/docs/automatic-https#hostname-requirements)
|
// [qualifying domain names](/docs/automatic-https#hostname-requirements)
|
||||||
// may trigger [automatic HTTPS](/docs/automatic-https), which automatically
|
// may trigger [automatic HTTPS](/docs/automatic-https), which automatically
|
||||||
// provisions and renews certificates for you. Before doing this, you
|
// provisions and renews certificates for you. Before doing this, you
|
||||||
|
@ -55,8 +55,8 @@ type (
|
||||||
// - In the middle, for a globular match (`/accounts/*/info`)
|
// - In the middle, for a globular match (`/accounts/*/info`)
|
||||||
//
|
//
|
||||||
// This matcher is fast, so it does not support regular expressions or
|
// This matcher is fast, so it does not support regular expressions or
|
||||||
// capture groups. For slower but more capable matching, use the path_regexp
|
// capture groups. For slower but more powerful matching, use the
|
||||||
// matcher.
|
// path_regexp matcher.
|
||||||
MatchPath []string
|
MatchPath []string
|
||||||
|
|
||||||
// MatchPathRE matches requests by a regular expression on the URI's path.
|
// MatchPathRE matches requests by a regular expression on the URI's path.
|
||||||
|
|
|
@ -54,24 +54,39 @@ func (StaticResponse) CaddyModule() caddy.ModuleInfo {
|
||||||
|
|
||||||
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
|
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
|
||||||
//
|
//
|
||||||
// respond [<matcher>] <status> {
|
// respond [<matcher>] [<status>|[<body> [<status>]] {
|
||||||
// body <text>
|
// body <text>
|
||||||
// close
|
// close
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
// If there is just one argument (other than the matcher), it is considered
|
||||||
|
// to be a status code if it's a valid positive integer of 3 digits.
|
||||||
func (s *StaticResponse) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
func (s *StaticResponse) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
for d.Next() {
|
for d.Next() {
|
||||||
var statusCodeStr string
|
args := d.RemainingArgs()
|
||||||
if d.Args(&statusCodeStr) {
|
switch len(args) {
|
||||||
s.StatusCode = WeakString(statusCodeStr)
|
case 1:
|
||||||
|
if len(args[0]) == 3 {
|
||||||
|
if num, err := strconv.Atoi(args[0]); err == nil && num > 0 {
|
||||||
|
s.StatusCode = WeakString(args[0])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.Body = args[0]
|
||||||
|
case 2:
|
||||||
|
s.Body = args[0]
|
||||||
|
s.StatusCode = WeakString(args[1])
|
||||||
|
default:
|
||||||
|
return d.ArgErr()
|
||||||
}
|
}
|
||||||
|
|
||||||
for d.NextBlock(0) {
|
for d.NextBlock(0) {
|
||||||
switch d.Val() {
|
switch d.Val() {
|
||||||
case "body":
|
case "body":
|
||||||
if s.Body != "" {
|
if s.Body != "" {
|
||||||
return d.Err("body already specified")
|
return d.Err("body already specified")
|
||||||
}
|
}
|
||||||
if !d.Args(&s.Body) {
|
if !d.AllArgs(&s.Body) {
|
||||||
return d.ArgErr()
|
return d.ArgErr()
|
||||||
}
|
}
|
||||||
case "close":
|
case "close":
|
||||||
|
|
Loading…
Reference in a new issue