Skip to content

mux: dedupe the Allow header on 405 responses#1096

Open
c-tonneslan wants to merge 1 commit into
go-chi:masterfrom
c-tonneslan:fix/dedupe-allow-header
Open

mux: dedupe the Allow header on 405 responses#1096
c-tonneslan wants to merge 1 commit into
go-chi:masterfrom
c-tonneslan:fix/dedupe-allow-header

Conversation

@c-tonneslan
Copy link
Copy Markdown

Closes #996.

`methodsAllowed` gets appended to once per matching tree branch, so when multiple overlapping wildcard routes (or a literal and a wildcard that match the same path) only differ by their pattern but share the same method, the resulting Allow header repeated that method per branch. The reporter's three-route setup produced `Allow: POST, POST, POST`.

Dedupe in `methodNotAllowedHandler` so each method shows up at most once. No change to the routing logic itself.

Added `TestMethodNotAllowed_DedupesAllowHeader` covering the regression.

methodsAllowed gets appended to once per matching tree branch, so
when multiple overlapping wildcard routes (or a literal and a
wildcard that match the same path) only differ by their pattern but
share the same method, the resulting Allow header repeated that
method per branch ("Allow: POST, POST, POST" for the reporter's
three-route setup).

Dedupe in methodNotAllowedHandler so each method shows up at most
once in the response. No change to the routing logic itself.

Closes go-chi#996.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate HTTP methods in 405 Allow header

1 participant