class AcceptEncoding < Split
- Inherits from
Split: #<<, #to_s, #sort_by_quality_factor, .parse, .coerce, .trailer?
The accept-encoding header represents a list of encodings that the client can accept.
Nested Classes and Modules
class EncodingA parsed content encoding entry with an optional quality factor.
Definitions
QVALUE = /0(\.[0-9]{0,3})?|1(\.[0]{0,3})?/
https://tools.ietf.org/html/rfc7231#section-5.3.1
ENCODING = /\A(?<name>#{TOKEN})(;q=(?<q>#{QVALUE}))?\z/
https://tools.ietf.org/html/rfc7231#section-5.3.4
def encodings
Parse the accept-encoding header value into a list of encodings.
Signature
-
returns
Array(Charset) the list of character sets and their associated quality factors.
Implementation
def encodings
self.map do |value|
if match = value.match(ENCODING)
Encoding.new(match[:name], match[:q])
else
raise ParseError.new("Could not parse encoding: #{value.inspect}")
end
end
end
def preferred_encodings
Parse the accept-encoding header and order encodings by preference.
Encodings with equal quality factors retain their original relative order.
Signature
-
returns
Array(Encoding) the preferred encodings.
Implementation
def preferred_encodings
sort_by_quality_factor(encodings)
end