Fallback to default_content if wildcard present in Accept header#21
Open
francois wants to merge 1 commit into
Open
Fallback to default_content if wildcard present in Accept header#21francois wants to merge 1 commit into
francois wants to merge 1 commit into
Conversation
If a browser makes a request like this:
Accept: text/csv,*.*
And the application is implemented like this:
set :default_content, :html
get "/" do
respond_to do |wants|
format.html { erb :home }
end
end
The request would return a 404, even though the caller specifically said
it was ready to accept any mime type.
I found this when building an API that does not return HTML: it returns
JSON or CSV, but browsers request HTML, XHTML and */*, in this order. By
catering to what the caller asked for, the API is more easily explorable
in a browser.
Author
|
This is actually incomplete. When the Accept header's first mime type is unknown, then we return the default, rather than the most appropriate type. For example: And a respond_to block of: The response will be HTML, and not CSV. In this case, it would be more appropriate to have CSV, since that's how the caller ordered the values. I'll work on this some more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a browser makes a request like this:
And the application is implemented like this:
The request would return a 404, even though the caller specifically said
it was ready to accept any mime type.
I found this when building an API that does not return HTML: it returns
JSON or CSV, but browsers request HTML, XHTML and /, in this order. By
catering to what the caller asked for, the API is more easily explorable
in a browser.
This change is