summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/staticresp.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-01-17 10:57:57 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2020-01-17 10:57:57 -0700
commit793a4058105bb4da2a03291c391a91a432d1893f (patch)
treee9599fac226b5a41dc5f84bd80112d93139bf2a0 /modules/caddyhttp/staticresp.go
parent85ff0e360408e67d8528e5e6240c345a79bf7021 (diff)
caddyhttp: Improve docs, and Caddyfile for respond directive
Diffstat (limited to 'modules/caddyhttp/staticresp.go')
-rw-r--r--modules/caddyhttp/staticresp.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go
index 0ca2f43..777ecb2 100644
--- a/modules/caddyhttp/staticresp.go
+++ b/modules/caddyhttp/staticresp.go
@@ -54,24 +54,39 @@ func (StaticResponse) CaddyModule() caddy.ModuleInfo {
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
//
-// respond [<matcher>] <status> {
+// respond [<matcher>] [<status>|[<body> [<status>]] {
// body <text>
// 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 {
for d.Next() {
- var statusCodeStr string
- if d.Args(&statusCodeStr) {
- s.StatusCode = WeakString(statusCodeStr)
+ args := d.RemainingArgs()
+ switch len(args) {
+ 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) {
switch d.Val() {
case "body":
if s.Body != "" {
return d.Err("body already specified")
}
- if !d.Args(&s.Body) {
+ if !d.AllArgs(&s.Body) {
return d.ArgErr()
}
case "close":