Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions modules/caddyhttp/reverseproxy/caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,8 @@ func (h *Handler) FinalizeUnmarshalCaddyfile(helper httpcaddyfile.Helper) error
d.Next()
args := d.RemainingArgs()

// TODO: Remove this check at some point in the future
if len(args) == 2 {
return d.Errf("configuring 'handle_response' for status code replacement is no longer supported. Use 'replace_status' instead.")
if isStatusReplacementPattern(matcher, subroute) {
return d.Errf("use 'replace_status' instead of 'handle_response' for status changes")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must use tabs

Suggested change
return d.Errf("use 'replace_status' instead of 'handle_response' for status changes")
return d.Errf("use 'replace_status' instead of 'handle_response' for status changes")

}

if len(args) > 1 {
Expand Down Expand Up @@ -986,6 +985,12 @@ func (h *Handler) FinalizeUnmarshalCaddyfile(helper httpcaddyfile.Helper) error
return nil
}

func isStatusReplacementPattern(m caddyhttp.ResponseMatcher) bool {
// If the matcher only checks status codes, and does not
// check headers, it's basically a status-only matcher.
return len(m.StatusCode) > 0 && len(m.Headers) == 0
}

// UnmarshalCaddyfile deserializes Caddyfile tokens into h.
//
// transport http {
Expand Down