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

feature - add Allow HTTP header to response for status code 405 #186

Open
bschwarz opened this issue Jul 1, 2021 · 2 comments
Open

feature - add Allow HTTP header to response for status code 405 #186

bschwarz opened this issue Jul 1, 2021 · 2 comments

Comments

@bschwarz
Copy link

bschwarz commented Jul 1, 2021

When lambda-api can not find a method for a path, it automatically sends back a HTTP 405 Method Not Allowed error, via MethodError. Per the HTTP rfc 7231, the Allow header must be sent back with the 405 response. I purpose adding this to lambda-api. I believe it can introspect and get the allowed methods, correct?

Thanks!

@bschwarz
Copy link
Author

bschwarz commented Jul 1, 2021

I can try to create a patch for this, if you just can point me in the right direction.

@bschwarz
Copy link
Author

bschwarz commented Jul 2, 2021

All I did was add the following line to requests.js, line 247:

this.app._headers.allow = Object.keys(routes['METHODS']).join(',') || ''

So the whole else block looks like this now:

this.app._errorStatus = 405
this.app._headers.allow = Object.keys(routes['METHODS']).join(',') || ''
throw new MethodError('Method not allowed',this.method,'/'+path.join('/'))

I am not sure if that's the best approach or not. I can whip up a patch file, or do a pull request if that is more convenient for you.

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

No branches or pull requests

1 participant