mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 22:53:34 +08:00
Middleware registered via Use() is prepended to the NoMethod handlers by rebuild405Handlers, so a global middleware that aborts the request answers before the NoMethod handler can reply. A middleware validating a header that only some methods carry therefore turns every 405 into its own error response. Add an opt-in Engine.SkipMethodNotAllowedMiddleware flag that runs only the NoMethod handlers for 405 responses. It is disabled by default, so existing behaviour is unchanged. The flag is resolved when the request is served rather than when the chain is built, so it applies regardless of the order in which Use(), NoMethod() and the flag are set. Requests handled by NoRoute() keep running the global middleware. Fixes #4189