Class: 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}))/
Constants inherited from Split
Class Method Summary collapse
-
.parse(value) ⇒ Object
Parses a raw header value.
-
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Adds one or more comma-separated values to the header.
-
#media_ranges ⇒ Object
Parse the ‘accept` header.
-
#to_s ⇒ Object
Converts the parsed header value into a raw header value.
Methods inherited from Split
Constructor Details
This class inherits a constructor from Protocol::HTTP::Header::Split
Class Method Details
.parse(value) ⇒ Object
Parses a raw header value.
75 76 77 |
# File 'lib/protocol/http/header/accept.rb', line 75 def self.parse(value) self.new(value.scan(SEPARATOR).map(&:strip)) end |
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
97 98 99 |
# File 'lib/protocol/http/header/accept.rb', line 97 def self.trailer? false end |
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.
104 105 106 107 108 |
# File 'lib/protocol/http/header/accept.rb', line 104 def media_ranges self.map do |value| self.parse_media_range(value) end end |
#to_s ⇒ Object
Converts the parsed header value into a raw header value.
91 92 93 |
# File 'lib/protocol/http/header/accept.rb', line 91 def to_s join(",") end |