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 ability to handle correctly OPTIONS and HEAD requests #578

Merged
merged 85 commits into from
May 17, 2022

Conversation

girardinsamuel
Copy link
Contributor

@girardinsamuel girardinsamuel commented Apr 8, 2022

This PR adds:

OPTIONS request handling

Before, if a route with OPTIONS had not been defined, a request to an existing route with OPTIONS method was returning a 404 Not Found. Now, it's returning a 204 No Content response with Allow headers containing the allowed request methods for this route.

(ref https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS#identifying_allowed_request_methods)

Method Not Allowed handling

Before if a route was accessed with wrong request method, it was returning a 404 Not Found. Now if the route exists but accessed with wrong methods, it will return a 405 Method Not Allowed exception with error message containing the allowed request methods for this route.

HEAD request handling

Before, if a route with HEAD had not been defined, a request to an existing route with HEAD method was returning a 404 Not Found. Now, it's returning a 204 No Content response with the headers that would have been sent if the request had been made with GET method.

(ref https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)

In addition, when defining a GET route, Masonite will automatically add a HEAD route for it.

Here is a summary with CURL commands against a Masonite app:
image

For this, two small features have been added:

  • adds withHeaders to response to add headers as a dict easily, as header() was one header by one and was not returning response class
  • adds ability to add headers to HTTP exception when rendering exceptions.

@girardinsamuel girardinsamuel mentioned this pull request Apr 8, 2022
5 tasks
Add database validation rules `exists_in_db` and `unique_in_db`
…/552

Added feature to share individual input validation errors in session
@girardinsamuel
Copy link
Contributor Author

@josephmancuso can you take a look at this? This PR is required for the CORS feature 😉.

@josephmancuso
Copy link
Member

code review good. Just want to test this manually before merging

@josephmancuso josephmancuso merged commit e4b4c63 into MasoniteFramework:4.0 May 17, 2022
@girardinsamuel girardinsamuel deleted the feat/options branch May 17, 2022 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Next Minor Non-breaking change that can go into the next minor version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants