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

How to add an "Allow" header to the response when a 405 error occures? #467

Closed
electrotype opened this issue Nov 23, 2020 · 2 comments · Fixed by #560
Closed

How to add an "Allow" header to the response when a 405 error occures? #467

electrotype opened this issue Nov 23, 2020 · 2 comments · Fixed by #560

Comments

@electrotype
Copy link

On a "method not allowed" (405) error, I'd like to be able to add a Allow header to the response. This header would contain the valid methods.

For example, if a path only supports GET requests, and a POST request is received, I'd like to be able to send a Allow: GET header.

Do you know how to achieve that?

@cdimascio
Copy link
Owner

cdimascio commented Nov 24, 2020

The validator should probably do this automatically. If you want to take a stab at it, you can have a peek here where the 405 is returned and think through how to add the allow header with the allowed http methods to the response.

Note, to do it via app code you could check for the 405 Method not allowed on your error middleware.

cdimascio added a commit that referenced this issue Dec 16, 2020
cdimascio added a commit that referenced this issue Dec 19, 2020
* feat: #467 support for URI path params

* update README

* update README

* feat: wildcard routes not found
ahilke added a commit to ahilke/express-openapi-validator that referenced this issue Mar 12, 2021
The Allow header must be sent if the server responds with 405 to
indicate which request methods can be used.

See cdimascio#467.
ahilke added a commit to ahilke/express-openapi-validator that referenced this issue Mar 12, 2021
The Allow header must be sent if the server responds with 405 to
indicate which request methods can be used.

See cdimascio#467
ahilke added a commit to ahilke/express-openapi-validator that referenced this issue Mar 12, 2021
Adds Allow header to 405 error. This is required by RFC 7231
and indicates which request methods can be used.

Resolves cdimascio#467
cdimascio pushed a commit that referenced this issue Mar 13, 2021
* chore: Fix Typos

* test: Add Test Case for Allow Header

The Allow header must be sent if the server responds with 405 to
indicate which request methods can be used.

See #467

* feat: Add Allow Header for 405 - Method Not Allowed

Adds Allow header to 405 error. This is required by RFC 7231
and indicates which request methods can be used.

Resolves #467

* doc: Adjust Error Handler in NestJS Example

When using a custom error handler like in the NestJS example, one needs
to set the headers on the response explicitly. The same is true when
using a custom express error handler.
@cdimascio
Copy link
Owner

available in v4.12.5

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 a pull request may close this issue.

2 participants