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 873c241
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/caddyhttp/reverseproxy/caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (h *Handler) ParseCaddyfileReverseProxy(helper httpcaddyfile.Helper) error
if len(val) == 3 && strings.HasSuffix(val, "xx") {
val = val[:1]
}
statusNum, err := strconv.Atoi(val[:1])
statusNum, err := strconv.Atoi(val)
if err != nil {
return d.Errf("bad status value '%s': %v", d.Val(), err)
}
Expand Down Expand Up @@ -481,7 +481,7 @@ func (h *Handler) ParseCaddyfileReverseProxy(helper httpcaddyfile.Helper) error
if len(arg) == 3 && strings.HasSuffix(arg, "xx") {
arg = arg[:1]
}
statusNum, err := strconv.Atoi(arg[:1])
statusNum, err := strconv.Atoi(arg)
if err != nil {
return d.Errf("bad status value '%s': %v", d.Val(), err)
}
Expand Down 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 {
if len(arg) == 3 && strings.HasSuffix(arg, "xx") {
arg = arg[:1]
}
statusNum, err := strconv.Atoi(arg)
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 873c241

Please sign in to comment.