-
Notifications
You must be signed in to change notification settings - Fork 15
accept-extension parameter support #12
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
base: master
Are you sure you want to change the base?
Conversation
|
Hey @kamui - please see the comment in the code about accept-extension. :) I'd love to include support for it but just haven't gotten around to it. The main problem with the code as it is now is that the Header class assumes that all subclasses only have qvalues, and doesn't account for extensions. Would be interested to hear any ideas you might have on how to refactor the code to accommodate extension values. |
|
Haha.. that code comment is hilarious. As far as solutions, it looks like only media types support accept-extensions, so you could probably keep the same api. I think for the Then in the How does that sound? |
|
Yeah, could definitely work. Although I think I'd like to keep the call to |
|
I've just started implementing it, but I'm not sure about the call to One of the snags I ran into is what to do with the Also, what should the API look like to access the extensions hash? |
…eader in a media type
… return a params hash based on the best matched media type
|
When you get a chance, take a look at my branch.
I suppose I would use it like this: # 'application/json;q=1;version=1.0'
accept = env['rack-accept.request'].media_type
media_type = accept.best_of('application/json', 'application/xml', 'text/html')
accept_params = accept.params(media_type)
puts accept_params['version'] # => '1.0'
puts accept_params['q] # => '1' |
|
What's the ETA on this? |
|
It's been 2 years, so I decided to cleanup/update some of the foundation (gemspec, minitest, guard, bundler, require instead of autoload) and release it as another gem with accept-extension support added. https://github.com/kamui/rack-accept_headers |
The http spec includes accept header extensions. So other than the
qvalue, you can actually add arbitrary parameters. We want to use accept-extensions for version api numbers. It looks like this:I wanted to use
rack-acceptsince it handles ordering by q values and filtering out the best type based on an array of supported media types, butrack-acceptassumes that the q value is the only parameter, and that it'll be right after the semicolon. If I use the header above, the result I get is this:rack-acceptthinks that the version is part of the media type. Also, since everything after the q value is thrown out, there's no way to get the other parameters, such as version without manually parsing out the raw Accept header.Looking at how
rack-acceptworks, you assume only the media type and the q value and you store them as a hash, but it would be cool if the media type returns were an array of hashes that looks like this:Resources:
http://www.informit.com/articles/article.aspx?p=1566460
http://publish.luisrei.com/articles/rest.html
http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html