class

HTTP::Cookies

Inherits Enumerable / Reference / Object

Represents a collection of cookies as it can be present inside a HTTP request or response.

NOTE: To use Cookies, you must explicitly import it with require "http/cookie"

Constructors

from_client_headers(headers : HTTP::Headers) : self

Creates a new instance by parsing the Cookie headers in the given HTTP::Headers.

See HTTP::Client::Response#cookies.

Source
from_headers(headers) : self

Creates a new instance by parsing the Cookie and Set-Cookie headers in the given HTTP::Headers.

See HTTP::Request#cookies and HTTP::Client::Response#cookies.

Source
from_server_headers(headers : HTTP::Headers) : self

Creates a new instance by parsing the Set-Cookie headers in the given HTTP::Headers.

See HTTP::Request#cookies.

Source
new

Creates a new empty instance.

Source

Instance methods

==(other : self)

Returns true if this reference is the same as other. Invokes same?.

add_request_headers(headers : HTTP::Headers) : HTTP::Headers

Adds Cookie headers for the cookies in this collection to the given HTTP::Headers instance and returns it. Removes any existing Cookie headers in it.

Source
add_response_headers(headers : HTTP::Headers) : HTTP::Headers

Adds Set-Cookie headers for the cookies in this collection to the given HTTP::Headers instance and returns it. Removes any existing Set-Cookie headers in it.

Source
empty?

Whether the collection contains any cookies.

Source
fill_from_client_headers(headers : HTTP::Headers) : self

Filling cookies by parsing the Cookie headers in the given HTTP::Headers.

Source
fill_from_headers(headers)

Filling cookies by parsing the Cookie and Set-Cookie headers in the given HTTP::Headers.

Source
fill_from_server_headers(headers : HTTP::Headers) : self

Filling cookies by parsing the Set-Cookie headers in the given HTTP::Headers.

Source
has_key?(key : String) : Bool

Returns true if a cookie with the given key exists.

request.cookies.has_key?("foo") # => true
Source
hash(hasher)

See Object#hash(hasher)

inspect(io : IO)

Returns a string representation of this cookies list.

It uses the Set-Cookie serialization from Cookie#to_set_cookie_header which represents the full state of the cookie.

HTTP::Cookies{
  HTTP::Cookie.new("foo", "bar"),
  HTTP::Cookie.new("foo", "bar", domain: "example.com"),
}.to_s # => "HTTP::Cookies{\"foo=bar\", \"foo=bar; domain=example.com\"}"
Source
pretty_print(pp) : Nil

Returns a string representation of this cookies list.

It uses the Set-Cookie serialization from Cookie#to_set_cookie_header which represents the full state of the cookie.

HTTP::Cookies{
  HTTP::Cookie.new("foo", "bar"),
  HTTP::Cookie.new("foo", "bar", domain: "example.com"),
}.to_s # => "HTTP::Cookies{\"foo=bar\", \"foo=bar; domain=example.com\"}"
Source
size

Returns the number of cookies contained in this collection.

Source
to_s(io : IO)

Returns a string representation of this cookies list.

It uses the Set-Cookie serialization from Cookie#to_set_cookie_header which represents the full state of the cookie.

HTTP::Cookies{
  HTTP::Cookie.new("foo", "bar"),
  HTTP::Cookie.new("foo", "bar", domain: "example.com"),
}.to_s # => "HTTP::Cookies{\"foo=bar\", \"foo=bar; domain=example.com\"}"
Source