Repository navigation
headers: Check each ? default on its own and keep the response matcher - #8217
Open
jayhemnani9910 wants to merge 4 commits into
Open
jayhemnani9910 wants to merge 4 commits into
jayhemnani9910 wants to merge 4 commits into
Conversation
Several ? defaults in one header block shared one require, so a single field already set on the response blocked all of them. A match in the block was also dropped for the ? fields, so they were set on every response.
steadytao
requested changes
Oct 14, 2026
A ? default already requires its field to be absent, so a match on the same field in that block could only be dropped or never be true. It is now a Caddyfile error.
steadytao
requested changes
Oct 15, 2026
Comment on lines
+151
to
+153
| if _, ok := defaultHandler.Response.Set[http.CanonicalHeaderKey(field)]; ok { | ||
| return nil, h.Errf("cannot match on response header %s and also set a default for it", http.CanonicalHeaderKey(field)) | ||
| } |
Member
There was a problem hiding this comment.
This also rejects match header !X-Test with ?X-Test fallback. A nil response-matcher value already requires the field to be absent so it is compatible with the default and previously adapted successfully.
Only reject same-field matchers that require a value. Preserve or deduplicate the absence matcher and add that case.
Contributor
Author
There was a problem hiding this comment.
Fixed in 13d7837. A !X-Test matcher next to ?X-Test loads again and is not added twice. Only a matcher that needs a value on that field is rejected. Added the !X-Absent / ?X-Absent case to TestHeaderDefaults, it fails on the previous commit.
Assistance Disclosure: AI used (Claude Code).
`match header !X-Test` asks for what `?X-Test` already requires, so it loads again. Only a matcher that needs a value on that field is an error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8216
In a
headerblock, all?fields shared onerequire, so one field already on the response stopped every default in the block. Amatchin the block was also left off the?fields, so they were set on every response.Each
?field now gets its own handler that requires only that field to be absent, plus thematchconditions when there are any. A block with a single?field adapts to the same JSON as before, so the existing adapt tests are unchanged.Test:
TestHeaderDefaultssetsCache-Controlfirst, then a block with?Cache-Controland?X-Frame-Options, and amatch status 404block with?X-Robots-Tag. Without the changeX-Frame-Optionsis missing andX-Robots-Tagis sent on a 200.go test ./...passes.Manual check with the config from the issue: v2.11.7 sends no
X-Frame-Optionson:18432andX-Robots-Tagon the 200 from:18434; with the changeX-Frame-Options: DENYis there and the 200 has noX-Robots-Tag.Assistance Disclosure
AI used (Claude Code).