Class: Protocol::HTTP::Header::Cookie
- Inherits:
-
Array
- Object
- Array
- Protocol::HTTP::Header::Cookie
- Defined in:
- lib/protocol/http/header/cookie.rb
Overview
The cookie header contains stored HTTP cookies previously sent by the server with the set-cookie header.
It is used by clients to send key-value pairs representing stored cookies back to the server.
Multiple cookies within a single Cookie header are joined with "; " per RFC 6265.
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
-
.parse(value) ⇒ Object
Parses a raw header value.
-
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
Instance Method Summary collapse
-
#initialize(value = nil) ⇒ Cookie
constructor
Initializes the cookie header with the given values.
-
#to_h ⇒ Object
Parses the
cookieheader into a hash of cookie names and their corresponding cookie objects. -
#to_s ⇒ Object
Serializes the
cookieheader by joining individual cookie strings with"; "per RFC 6265.
Constructor Details
#initialize(value = nil) ⇒ Cookie
Initializes the cookie header with the given values.
40 41 42 43 44 45 46 |
# File 'lib/protocol/http/header/cookie.rb', line 40 def initialize(value = nil) super() if value self.concat(value) end end |
Class Method Details
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
28 29 30 31 32 33 34 35 |
# File 'lib/protocol/http/header/cookie.rb', line 28 def self.coerce(value) case value when Array self.new(value.map(&:to_s)) else self.parse(value.to_s) end end |
.parse(value) ⇒ Object
Parses a raw header value.
20 21 22 |
# File 'lib/protocol/http/header/cookie.rb', line 20 def self.parse(value) self.new([value]) end |
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers. Cookie headers should not appear in trailers as they contain state information needed early in processing.
67 68 69 |
# File 'lib/protocol/http/header/cookie.rb', line 67 def self.trailer? false end |
Instance Method Details
#to_h ⇒ Object
Parses the cookie header into a hash of cookie names and their corresponding cookie objects.
51 52 53 54 55 56 57 |
# File 'lib/protocol/http/header/cookie.rb', line 51 def to_h = self.collect do |string| HTTP::Cookie.parse(string) end .map{|| [.name, ]}.to_h end |
#to_s ⇒ Object
Serializes the cookie header by joining individual cookie strings with "; " per RFC 6265.
60 61 62 |
# File 'lib/protocol/http/header/cookie.rb', line 60 def to_s join("; ") end |