Class: Rack::Request
- Inherits:
-
Object
- Object
- Rack::Request
- Defined in:
- lib/rack/acceptable.rb
Defined Under Namespace
Classes: AcceptableMediaTypes
Instance Method Summary collapse
-
#acceptable_media_types ⇒ Object
The media types of the HTTP_ACCEPT header ordered according to their “quality” (preference level), without any media type parameters.
Instance Method Details
#acceptable_media_types ⇒ Object
The media types of the HTTP_ACCEPT header ordered according to their “quality” (preference level), without any media type parameters.
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'
For more information, see:
-
Accept header: www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
-
Quality values: www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
Returns
- AcceptableMediaTypes
-
ordered list of accept header’s media types
30 31 32 |
# File 'lib/rack/acceptable.rb', line 30 def acceptable_media_types @acceptable_media_types ||= AcceptableMediaTypes.new(@env['HTTP_ACCEPT']) end |