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

Support for parameters in mime types. #1256

Conversation

JonMidhir
Copy link
Contributor

Fixes #1141.

Adds support for parameters when creating new mime types.

Previously, the user could declare a mime type with parameters like this:

configure do
  mime_type :rss10, 'application/rss+xml; version="http://purl.org/rss/1.0/"'
end

get '/feed', :provides => [:rss10] do
  # ...
end

But the route would 404 when the version was missing from the accept header:

curl -H 'Accept: application/rss+xml' -I [host]/feed

HTTP/1.1 404 Not Found 
Content-Type: text/html;charset=utf-8

This change allows the route to respond, including the more specific parameters in the Content-Type header.

curl -H 'Accept: application/rss+xml' -I [host]/feed

HTTP/1.1 200 OK 
Content-Type: application/rss+xml; version="http://purl.org/rss/1.0/"

Accept headers that include all, some or none of the specified parameters are OK, but those that specify different values are not.

configure do
  mime_type :rss10, 'application/rss+xml; version="http://purl.org/rss/1.0/"; charset=utf-8'
end
# OK
curl -H 'Accept: application/rss+xml' -I [host]/feed
curl -H 'Accept: application/rss+xml; version="http://purl.org/rss/1.0/"' -I [host]/feed
curl -H 'Accept: application/rss+xml; version="http://purl.org/rss/1.0/"; charset=utf-8' -I [host]/feed
curl -H 'Accept: application/rss+xml; charset=utf-8; something=else' -I [host]/feed

# Not OK
curl -H 'Accept: application/rss+xml; version="https://cyber.harvard.edu/rss/rss.html"' -I [host]/feed

@zzak
Copy link
Member

zzak commented Mar 4, 2017

Thank you @JonMidhir!

I'd like to consider this for after a 2.0 release.

@zzak zzak added this to the Beyond milestone Mar 4, 2017
@JonMidhir JonMidhir force-pushed the issue#1141-support_for_parameters_in_mime_types branch from 49b5324 to 7dbd443 Compare March 7, 2017 10:29
@JonMidhir JonMidhir force-pushed the issue#1141-support_for_parameters_in_mime_types branch from 7dbd443 to 449a393 Compare June 3, 2017 19:29
@JonMidhir
Copy link
Contributor Author

Noticed a few stray commits in this, rebased them so it's much simpler now. Also, master had moved on a fair bit 😂

@namusyaka namusyaka modified the milestones: Beyond, v2.1.0 Mar 6, 2018
@namusyaka
Copy link
Member

Marked as v2.1.0.

@jkowens jkowens merged commit 574e5a9 into sinatra:master Mar 13, 2020
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.

Sinatra::RespondWith providing mime_type and Accept header
4 participants