aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/reverseproxy/caddyfile.go
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2022-05-02 13:44:28 -0400
committerGitHub <[email protected]>2022-05-02 11:44:28 -0600
commit4a223f52038cb77bbf97ca3f3345550dea4e12d8 (patch)
treeda1eb2b18a257fc0bfea86cf45e1ca14fc4f28a6 /modules/caddyhttp/reverseproxy/caddyfile.go
parentaf7321511c960120d61cfd22e031f43071d5a9c2 (diff)
downloadcaddy-4a223f52038cb77bbf97ca3f3345550dea4e12d8.tar.gz
caddy-4a223f52038cb77bbf97ca3f3345550dea4e12d8.zip
reverseproxy: Fix Caddyfile support for `replace_status` (#4754)
Diffstat (limited to 'modules/caddyhttp/reverseproxy/caddyfile.go')
-rw-r--r--modules/caddyhttp/reverseproxy/caddyfile.go33
1 files changed, 16 insertions, 17 deletions
diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go
index b3f901060..14de23002 100644
--- a/modules/caddyhttp/reverseproxy/caddyfile.go
+++ b/modules/caddyhttp/reverseproxy/caddyfile.go
@@ -627,22 +627,24 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
case "replace_status":
args := d.RemainingArgs()
- if len(args) != 2 {
- return d.Errf("must have two arguments: a response matcher and a status code")
+ if len(args) != 1 && len(args) != 2 {
+ return d.Errf("must have one or two arguments: an optional response matcher, and a status code")
}
- if !strings.HasPrefix(args[0], matcherPrefix) {
- return d.Errf("must use a named response matcher, starting with '@'")
- }
-
- foundMatcher, ok := h.responseMatchers[args[0]]
- if !ok {
- return d.Errf("no named response matcher defined with name '%s'", args[0][1:])
- }
+ responseHandler := caddyhttp.ResponseHandler{}
- _, err := strconv.Atoi(args[1])
- if err != nil {
- return d.Errf("bad integer value '%s': %v", args[1], err)
+ if len(args) == 2 {
+ if !strings.HasPrefix(args[0], matcherPrefix) {
+ return d.Errf("must use a named response matcher, starting with '@'")
+ }
+ foundMatcher, ok := h.responseMatchers[args[0]]
+ if !ok {
+ return d.Errf("no named response matcher defined with name '%s'", args[0][1:])
+ }
+ responseHandler.Match = &foundMatcher
+ responseHandler.StatusCode = caddyhttp.WeakString(args[1])
+ } else if len(args) == 1 {
+ responseHandler.StatusCode = caddyhttp.WeakString(args[0])
}
// make sure there's no block, cause it doesn't make sense
@@ -652,10 +654,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
h.HandleResponse = append(
h.HandleResponse,
- caddyhttp.ResponseHandler{
- Match: &foundMatcher,
- StatusCode: caddyhttp.WeakString(args[1]),
- },
+ responseHandler,
)
default: