Skip to content

Commit

Permalink
reverseproxy: Fix support for "4xx" type status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Feb 18, 2021
1 parent 0a5c6e3 commit 8c2dde1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/caddyhttp/reverseproxy/caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ func (h *Handler) parseNamedResponseMatcher(d *caddyfile.Dispenser, matchers map
}

matcher.Headers = http.Header(headerMatcher)

case "status":
if matcher.StatusCode == nil {
matcher.StatusCode = []int{}
Expand All @@ -1023,12 +1024,16 @@ func (h *Handler) parseNamedResponseMatcher(d *caddyfile.Dispenser, matchers map
}

for _, arg := range args {
statusNum, err := strconv.Atoi(arg)
if len(arg) == 3 && strings.HasSuffix(arg, "xx") {
arg = arg[:1]
}
statusNum, err := strconv.Atoi(arg[:1])
if err != nil {
return d.Errf("bad status value '%s': %v", arg, err)
}
matcher.StatusCode = append(matcher.StatusCode, statusNum)
}

default:
return d.Errf("unrecognized response matcher %s", d.Val())
}
Expand Down

0 comments on commit 8c2dde1

Please sign in to comment.