Class: Protocol::HTTP::Header::Accept
- Inherits:
-
Array
- Object
- Array
- Protocol::HTTP::Header::Accept
- Defined in:
- lib/protocol/http/header/accept.rb
Overview
The ‘accept-content-type` header represents a list of content-types that the client can accept.
Defined Under Namespace
Classes: MediaRange
Constant Summary collapse
- SEPARATOR =
Regular expression used to split values on commas, with optional surrounding whitespace, taking into account quoted strings.
/ (?: # Start non-capturing group "[^"\\]*" # Match quoted strings (no escaping of quotes within) | # OR [^,"]+ # Match non-quoted strings until a comma or quote )+ (?=,|\z) # Match until a comma or end of string /x
- ParseError =
Class.new(Error)
- MEDIA_RANGE =
/\A(?<type>#{TOKEN})\/(?<subtype>#{TOKEN})(?<parameters>.*)\z/
- PARAMETER =
/\s*;\s*(?<key>#{TOKEN})=((?<value>#{TOKEN})|(?<quoted_value>#{QUOTED_STRING}))/
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Adds one or more comma-separated values to the header.
-
#initialize(value = nil) ⇒ Accept
constructor
Parse the ‘accept` header value into a list of content types.
-
#media_ranges ⇒ Object
Parse the ‘accept` header.
-
#to_s ⇒ Object
Serializes the stored values into a comma-separated string.
Constructor Details
Instance Method Details
#<<(value) ⇒ Object
Adds one or more comma-separated values to the header.
The input string is split into distinct entries and appended to the array.
84 85 86 |
# File 'lib/protocol/http/header/accept.rb', line 84 def << (value) self.concat(value.scan(SEPARATOR).map(&:strip)) end |
#media_ranges ⇒ Object
Parse the ‘accept` header.
98 99 100 101 102 |
# File 'lib/protocol/http/header/accept.rb', line 98 def media_ranges self.map do |value| self.parse_media_range(value) end end |
#to_s ⇒ Object
Serializes the stored values into a comma-separated string.
91 92 93 |
# File 'lib/protocol/http/header/accept.rb', line 91 def to_s join(",") end |