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

Fixed issues related to invalid accept headers #913

Conversation

croeck
Copy link
Contributor

@croeck croeck commented Jan 30, 2015

Fixed that invalid accept headers are (1) not processed by rescue handlers and (2) result in status 500 (no method) when http_codes are defined. The fix is based on changing the former throw to raising a new error, which then can be processed.

To (1):
The actual behavior of cascading the request remains unchanged as the headers are included in the raised error. As long as the error is not rescued it results in the same error messages (404 or 406).
The error message that is generated consists of two parts: The problem Invalid accept header and what actually went wrong, eg. API vendor or version not found. The cause of the problem was included as the resolution of the problem, as it always describes what the user did wrong:

  • Accept header must be set
  • Accept header must not contain ranges ("*")
  • 406 Not Acceptable <-- not quite perfect, shouldn't it be No matching media type found ?
  • API vendor or version not found
  • The error message when Rack::Accept::MediaType.new env['HTTP_ACCEPT'] fails

To (2):
As commented in the source code, lib/grape/error_formatter/base.rb does raise an error if the failure originated from the middleware and not a route. All the throw statements that were used before have caused those errors if http_codes were defined in the route description.

Please let me know if there are any issues with these changes.
Cedric

@croeck croeck force-pushed the invalid-accept-header-not-processed-by-handlers branch from ff71366 to f5ea8a0 Compare January 30, 2015 14:00
@@ -9,6 +9,7 @@ Next Release
* [#901](https://github.com/intridea/grape/pull/901): Fix: callbacks defined in a version block are only called for the routes defined in that block - [@kushkella](https://github.com/kushkella).
* [#886](https://github.com/intridea/grape/pull/886): Group of parameters made to require an explicit type of Hash or Array - [@jrichter1](https://github.com/jrichter1).
* [#912](https://github.com/intridea/grape/pull/912): Extended the `:using` feature for param documentation to `optional` fields - [@croeck](https://github.com/croeck).
* [#913](https://github.com/intridea/grape/pull/913): Fix: Invalid accept headers are (1) not processed by rescue handlers and (2) result in 500 when http_codes are defines - [@croeck](https://github.com/croeck).
Copy link
Member

Choose a reason for hiding this comment

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

Typo: defineD, right?

You can split this into two separate lines, to avoid the whole (1) (2) thing even if it means repeating #913.

@dblock
Copy link
Member

dblock commented Jan 30, 2015

Solid, nice work @croeck. Amend by my nitpicky comments and I'll merge.

…dlers and (2) result in status 500 (no method) when http_codes are defined.
@croeck croeck force-pushed the invalid-accept-header-not-processed-by-handlers branch from f5ea8a0 to 0dea522 Compare January 30, 2015 21:39
@croeck
Copy link
Contributor Author

croeck commented Jan 30, 2015

Changes are now included, thanks for your comments!

@dblock
Copy link
Member

dblock commented Jan 31, 2015

Merged rebased via 046450e. Thank 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

Successfully merging this pull request may close these issues.

2 participants