Adds an #acceptable_media_types to Rack::Request for conneg
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
benchmarks
lib/rack
spec
.document
.gitignore
LICENSE
README.mkd
Rakefile
rack-acceptable.gemspec

README.mkd

rack-acceptable

Adds a #acceptable_media_types method to Rack::Request objects so that full-featured content-negotiation can be performed.

Examples

env['HTTP_ACCEPT']  #=> 'application/xml;q=0.8,text/html,text/plain;q=0.9'

req = Rack::Request.new(env)
req.acceptable_media_types          #=> ['text/html', 'text/plain', 'application/xml']

req.acceptable_media_types.prioritize('application/xml', 'text/html') #=>  ['text/html', application/xml']
req.acceptable_media_types.preference_of('text/plain', 'text/html')   #=>  'text/html'
req.acceptable_media_types.first_acceptable('image/png', 'text/html') #=>  'text/html'

See spec/acceptable_media_types_spec.rb for more.