Class: Protocol::HTTP::Header::Cookie

Inherits:
Multiple
  • Object
show all
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.

Direct Known Subclasses

SetCookie

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Multiple

coerce, #initialize, parse, #to_s

Constructor Details

This class inherits a constructor from Protocol::HTTP::Header::Multiple

Class Method Details

.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.

Returns:

  • (Boolean)


30
31
32
# File 'lib/protocol/http/header/cookie.rb', line 30

def self.trailer?
	false
end

Instance Method Details

#to_hObject

Parses the ‘cookie` header into a hash of cookie names and their corresponding cookie objects.



19
20
21
22
23
24
25
# File 'lib/protocol/http/header/cookie.rb', line 19

def to_h
	cookies = self.collect do |string|
		HTTP::Cookie.parse(string)
	end
	
	cookies.map{|cookie| [cookie.name, cookie]}.to_h
end