Class Rack::Accept::Request
In: lib/rack/accept/request.rb
Parent: Rack::Request

A container class for convenience methods when Rack::Accept is used on the request level as Rack middleware. Instances of this class also manage a lightweight cache of various header instances to speed up execution.

Methods

Attributes

env  [R] 

Public Class methods

[Source]

    # File lib/rack/accept/request.rb, line 10
10:     def initialize(env)
11:       @env = env
12:     end

Public Instance methods

Determines the best character set to use in a response from the given character sets, if any is acceptable. For more information on how this value is determined, see the documentation for Rack::Accept::Header::PublicInstanceMethods#sort.

[Source]

    # File lib/rack/accept/request.rb, line 70
70:     def best_charset(values)
71:       charset.best_of(values)
72:     end

Determines the best encoding to use in a response from the given encodings, if any is acceptable. For more information on how this value is determined, see the documentation for Rack::Accept::Header::PublicInstanceMethods#sort.

[Source]

    # File lib/rack/accept/request.rb, line 78
78:     def best_encoding(values)
79:       encoding.best_of(values)
80:     end

Determines the best language to use in a response from the given languages, if any is acceptable. For more information on how this value is determined, see the documentation for Rack::Accept::Header::PublicInstanceMethods#sort.

[Source]

    # File lib/rack/accept/request.rb, line 86
86:     def best_language(values)
87:       language.best_of(values)
88:     end

Determines the best media type to use in a response from the given media types, if any is acceptable. For more information on how this value is determined, see the documentation for Rack::Accept::Header::PublicInstanceMethods#sort.

[Source]

    # File lib/rack/accept/request.rb, line 62
62:     def best_media_type(values)
63:       media_type.best_of(values)
64:     end

Provides access to the Rack::Accept::Charset instance for this request.

[Source]

    # File lib/rack/accept/request.rb, line 20
20:     def charset
21:       @charset ||= Charset.new(env['HTTP_ACCEPT_CHARSET'])
22:     end

Returns true if the +Accept-Charset+ request header indicates the given character set is acceptable, false otherwise.

[Source]

    # File lib/rack/accept/request.rb, line 42
42:     def charset?(value)
43:       charset.accept?(value)
44:     end

Provides access to the Rack::Accept::Encoding instance for this request.

[Source]

    # File lib/rack/accept/request.rb, line 25
25:     def encoding
26:       @encoding ||= Encoding.new(env['HTTP_ACCEPT_ENCODING'])
27:     end

Returns true if the +Accept-Encoding+ request header indicates the given encoding is acceptable, false otherwise.

[Source]

    # File lib/rack/accept/request.rb, line 48
48:     def encoding?(value)
49:       encoding.accept?(value)
50:     end

Provides access to the Rack::Accept::Language instance for this request.

[Source]

    # File lib/rack/accept/request.rb, line 30
30:     def language
31:       @language ||= Language.new(env['HTTP_ACCEPT_LANGUAGE'])
32:     end

Returns true if the +Accept-Language+ request header indicates the given language is acceptable, false otherwise.

[Source]

    # File lib/rack/accept/request.rb, line 54
54:     def language?(value)
55:       language.accept?(value)
56:     end

Provides access to the Rack::Accept::MediaType instance for this request.

[Source]

    # File lib/rack/accept/request.rb, line 15
15:     def media_type
16:       @media_type ||= MediaType.new(env['HTTP_ACCEPT'])
17:     end

Returns true if the Accept request header indicates the given media type is acceptable, false otherwise.

[Source]

    # File lib/rack/accept/request.rb, line 36
36:     def media_type?(value)
37:       media_type.accept?(value)
38:     end

[Validate]