Skip to content
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

Add function to expose allowed methods for use in custom 405-handlers #884

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flimzy
Copy link
Contributor

@flimzy flimzy commented Dec 14, 2023

Fixes #870

context.go Outdated
Comment on lines 40 to 46
if rctx := RouteContext(ctx); rctx != nil {
result := make([]string, 0, len(rctx.methodsAllowed))
for _, method := range rctx.methodsAllowed {
if method := methodTypString(method); method != "" {
result = append(result, method)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, do you think it'd make sense to expose a method on rctx instead?

rctx := chi.RouteContext(ctx)

var methods []string = rctx.AllowedMethods()

Copy link
Contributor Author

@flimzy flimzy Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would serve my purpose just as well. I'm happy to update the PR, if that would get it merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good :) thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the requested change, and rebased on a current version of the master branch.

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.

Feature: Expose Context.methodsAllowed for use by MethodNotAllowedHandler
2 participants