Skip to content
Rack convenience middleware for simplified handling of Accept header (Accept header parser).
Ruby
Find file
Latest commit 3d0f388 Apr 24, 2010 @enricob enricob committed with Filter spaces out of the header string passed in so that the individu…
…al media types don't have extraneous whitespace.
Failed to load latest commit information.
lib/rack
test Filter spaces out of the header string passed in so that the individu… Apr 26, 2010
.gitignore
LICENSE
Manifest
README.md
Rakefile
examples.rb
rack-accept-media-types.gemspec
specs.watchr Simplify gem handling Nov 21, 2009

README.md

Summary

Rack convenience middleware to simplify handling of Accept header env['HTTP_ACCEPT']. Allows ordering of its values (accepted media types) according to their "quality" (preference level).

This wrapper is typically used to determine the request's prefered media type.

Install

gem install rack-accept-media-types

Example

require 'rack/accept_media_types'

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

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

Links

Something went wrong with that request. Please try again.