Class: Rack::Accept::Encoding
- Inherits:
-
Object
- Object
- Rack::Accept::Encoding
- Includes:
- Header
- Defined in:
- lib/rack/accept/encoding.rb
Overview
Represents an HTTP Accept-Encoding header according to the HTTP 1.1 specification, and provides several convenience methods for determining acceptable content encodings.
Instance Attribute Summary
Attributes included from Header::PublicInstanceMethods
Instance Method Summary collapse
-
#matches(encoding) ⇒ Object
Returns an array of encodings from this header that match the given
encoding, ordered by precedence. -
#name ⇒ Object
The name of this header.
-
#qvalue(encoding) ⇒ Object
Determines the quality factor (qvalue) of the given
encoding.
Methods included from Header
join, normalize_qvalue, parse, parse_media_type, parse_range_params
Methods included from Header::PublicInstanceMethods
#accept?, #best_of, #initialize, #sort, #sort_with_qvalues, #to_s, #value, #values
Instance Method Details
#matches(encoding) ⇒ Object
Returns an array of encodings from this header that match the given encoding, ordered by precedence.
27 28 29 30 31 32 33 34 |
# File 'lib/rack/accept/encoding.rb', line 27 def matches(encoding) values.select {|v| v == encoding || v == '*' }.sort {|a, b| # "*" gets least precedence, any others should be equal. a == '*' ? 1 : (b == '*' ? -1 : 0) } end |
#name ⇒ Object
The name of this header.
11 12 13 |
# File 'lib/rack/accept/encoding.rb', line 11 def name 'Accept-Encoding' end |
#qvalue(encoding) ⇒ Object
Determines the quality factor (qvalue) of the given encoding.
16 17 18 19 20 21 22 23 |
# File 'lib/rack/accept/encoding.rb', line 16 def qvalue(encoding) m = matches(encoding) if m.empty? encoding == 'identity' ? 1 : 0 else normalize_qvalue(@qvalues[m.first]) end end |