Skip to content

fix: deduplicate Allow header in 405 Method Not Allowed responses#1124

Open
happysnaker wants to merge 1 commit into
go-chi:masterfrom
happysnaker:fix-405-allow-dedup
Open

fix: deduplicate Allow header in 405 Method Not Allowed responses#1124
happysnaker wants to merge 1 commit into
go-chi:masterfrom
happysnaker:fix-405-allow-dedup

Conversation

@happysnaker

Copy link
Copy Markdown
Contributor

Summary

Fixes #996

When multiple routes with the same HTTP method but different patterns are registered (e.g., /article/{a}, /article/{b}-{c}, /article/{b}-{c}-{d}), the Allow header in 405 responses contains duplicate method entries like:

Allow: POST, POST, POST, POST

Changes

  • Added deduplication in methodNotAllowedHandler using a seen map to track methods already added to the Allow header
  • Added test case to verify deduplication

Before

Allow: POST, POST, POST, POST

After

Allow: POST

When multiple routes with the same HTTP method but different patterns
are registered (e.g., /article/{a} and /article/{b}-{c}), the Allow header
in 405 responses contains duplicate method entries.

This commit deduplicates the Allow header by tracking seen methods.

Fixes go-chi#996
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