Skip to content

reverseproxy: fix misleading handle_response error for extra matcher args - #7869

Merged
francislavoie merged 1 commit into
caddyserver:masterfrom
TowyTowy:fix/6529-handle-response-arg-error
Jul 10, 2026
Merged

francislavoie merged 1 commit into
caddyserver:masterfrom
TowyTowy:fix/6529-handle-response-arg-error

Conversation

@TowyTowy

@TowyTowy TowyTowy commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #6529

Per @steadytao's go-ahead on the issue, this implements exactly the fix @francislavoie specced in his review of #7709: reject more than a single argument to handle_response, and stop referencing replace_status in the error message, stating instead that only a single response matcher name token is allowed.

Previously, handle_response header Foo { ... } tripped an obsolete two-argument check (left over from the long-removed inline status-code-replacement syntax, marked // TODO: Remove this check at some point in the future) and confusingly told the user to use replace_status even though no status replacement was involved.

Changes:

  • Remove the obsolete len(args) == 2 special case and its replace_status explanation.
  • The existing len(args) > 1 check now covers all excess-argument cases with an accurate message: too many arguments for 'handle_response': only a single response matcher name is allowed, but got: [header Foo].
  • Add a Caddyfile adapt test (reverse_proxy_handle_response_too_many_args.caddyfiletest) for the exact case reported in Including matcher in 'handle_response' line has confusing error #6529, following the existing error-asserting adapt test convention. It fails on current master (old misleading message) and passes with this change.

This intentionally supersedes #7709, which has been idle and took a different direction than the reviewed suggestion — thanks to @suryaanshah for the earlier effort there. Note the same obsolete check also exists in the intercept directive (modules/caddyhttp/intercept/intercept.go); left untouched here to keep this PR focused on the reported case, happy to follow up separately if desired.

go test ./caddytest/integration/ -run TestCaddyfileAdaptToJSON and go test ./modules/caddyhttp/reverseproxy/ both pass; gofmt clean.

Assistance Disclosure

This change was implemented with the assistance of Claude (Anthropic's LLM) via Claude Code: it drafted the code change and the adapt test under my direction, following the exact approach specified by the maintainers in #6529 / the #7709 review. I have read, fully understand, and take responsibility for every line, and verified the fix with a fail-before/pass-after test run.

…args

Passing more than one argument to handle_response (e.g.
'handle_response header Foo') hit an obsolete check for the removed
inline status-code-replacement syntax and produced a confusing error
telling the user to use 'replace_status' instead.

Drop that obsolete check and reject any argument count greater than
one with an accurate message stating that only a single named response
matcher is allowed. Add a Caddyfile adapt test for the reported case.

Fixes caddyserver#6529

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Jul 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@francislavoie francislavoie added the documentation 📚 Improvements or additions to documentation label Jul 10, 2026
@francislavoie francislavoie added this to the v2.11.5 milestone Jul 10, 2026

@francislavoie francislavoie left a comment

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.

Thanks, yep that looks right to me.

@francislavoie
francislavoie enabled auto-merge (squash) July 10, 2026 05:36
@francislavoie
francislavoie merged commit 945d199 into caddyserver:master Jul 10, 2026
26 checks passed
steadytao pushed a commit that referenced this pull request Jul 11, 2026
#7871)

Same obsolete two-argument check as the reverse_proxy one removed in
#7869: it referenced the long-removed inline status-code-replacement
syntax and pointed users at replace_status even when no status
replacement was involved. The generic check now rejects all
excess-argument cases with an accurate message.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 📚 Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Including matcher in 'handle_response' line has confusing error

3 participants