Skip to content

Conversation

@nathannewyen
Copy link

@nathannewyen nathannewyen commented Dec 19, 2025

Summary

  • Fixes duplicate HTTP methods appearing in the Allow header of 405 responses
  • When multiple overlapping wildcard routes match a path, each matching node was adding its methods to the Allow header, causing duplicates like Allow: POST POST POST POST
  • This fix uses a map to track seen methods and only adds each unique method once

Reproduction

As described in the issue, when routes overlap due to wildcards:

r.Post("/article/1-2-3", handler)
r.Post("/article/{a}", handler)
r.Post("/article/{b}-{c}", handler)
r.Post("/article/{b}-{c}-{d}", handler)

A GET request to /article/1-2-3 previously returned:

Allow: POST POST POST POST

Now correctly returns:

Allow: POST

Test plan

  • Added TestMethodNotAllowedDuplicateMethods test case
  • All existing tests pass

Fixes #996

When multiple overlapping wildcard routes match the same path, the Allow
header in 405 responses was containing duplicate HTTP methods (e.g.,
"POST POST POST POST" instead of just "POST").

This fix uses a map to track seen methods and only adds each method once
to the Allow header.

Fixes go-chi#996
@nathannewyen nathannewyen force-pushed the fix-duplicate-allow-header branch from 9001d00 to d95a851 Compare December 19, 2025 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant