Skip to content

fix(router): optional StrictRouting for static 405 precedence - #1136

Open
Solaris-star wants to merge 1 commit into
go-chi:masterfrom
Solaris-star:fix/1035-static-method-not-allowed-precedence
Open

fix(router): optional StrictRouting for static 405 precedence#1136
Solaris-star wants to merge 1 commit into
go-chi:masterfrom
Solaris-star:fix/1035-static-method-not-allowed-precedence

Conversation

@Solaris-star

@Solaris-star Solaris-star commented Jul 21, 2026

Copy link
Copy Markdown

Summary

If /users/me is registered for GET and /users/{id} for PUT, a PUT /users/me currently falls through to the param route (id=me) instead of returning 405 for the exact static path (#1035).

Historical chi behavior (see TestTreeMoar) intentionally allows method fallthrough to param siblings in some cases, so this is opt-in.

Fix

  • Add Mux.StrictRouting(bool)
  • When enabled, an exact static leaf that matches the path but not the method sets 405 and stops searching less-specific param/regexp siblings

Test plan

  • go test ./...
  • New TestStaticRouteMethodNotAllowedOverParam (with StrictRouting(true))
  • Existing TestTreeMoar still passes with default (false)

Fixes #1035

When StrictRouting is enabled, an exact static path that exists for other
methods returns 405 instead of falling through to a param/regexp sibling
(e.g. PUT /users/me no longer matches PUT /users/{id}).

Default remains false to preserve historical chi behavior covered by
TestTreeMoar.

Fixes go-chi#1035
@Solaris-star
Solaris-star force-pushed the fix/1035-static-method-not-allowed-precedence branch from 09c4bf6 to b7f10a9 Compare July 21, 2026 12:36
@Solaris-star Solaris-star changed the title fix(router): prefer static path 405 over param sibling routes fix(router): optional StrictRouting for static 405 precedence Jul 21, 2026
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.

Expecting 405, getting routed to a param path instead

1 participant