-
-
Notifications
You must be signed in to change notification settings - Fork 989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include Allow header in 405 Method Not Allowed response #446
Comments
I'd recommend to implement this kind of behavior as a middleware where it will test for the route by accessing the router directly, and if not found, you can include the methods which are supported. As much as the RFC is cool, I don't see that this should be a "requirement" |
@pkieltyka I've looked through the docs but I can't see how to get this information from the router. Could you point me in the right direction? Or do you mean that the middleware would need to contain its own secondary mapping of paths to available HTTP methods to perform the lookup? |
nudge @pkieltyka, I'm also interested in answers to ☝️. |
your middleware could function similarly to GetHead where it would do a quick-pass to search the router for the method, serve if found, otherwise compile a list of methods on the route which are available instead and handle the response https://github.com/go-chi/chi/blob/master/middleware/get_head.go#L24-L35 for how to search the router in a middleware |
@pkieltyka It's this part that I don't get. It sounds like we would need to maintain a separate listing of all routes and their available methods. Is that what you're suggesting, or do I misunderstand? I'm happy to dig into the code to see if there's a way to achieve this without making any breaking changes 🙂 But I don't want to waste the time on that if there's no desire to fix the issue? |
just curious, but why are you so keen on this feature? |
@alexedwards it is possible, see the GetHead middleware, its all there for you if you desire. Jump into the code and play around |
I am interested in this too. Currently, Is there another method that returns |
At the moment the default methodNotAllowedHandler doesn't include an
Allow
header containing the resource's supported methods.I've made a minimal runnable example here: https://play.golang.org/p/CSUjlf8e30S
According to the HTTP RFC the
Allow
header must be included in 405 responses, so it would be good if there is a way that chi could support this.The text was updated successfully, but these errors were encountered: