Represents a collection of cookies as it can be present inside a HTTP request or response.
Creates a new instance by parsing the Cookie and Set-Cookie headers in the given HTTP::Headers.
Creates a new empty instance.
Adds the given cookie to this collection, overrides an existing cookie with the same name if present.
Gets the current HTTP::Cookie for the given key.
Sets a new cookie in the collection with a string value.
Sets a new cookie in the collection to the given HTTP::Cookie instance.
Gets the current HTTP::Cookie for the given key or nil if none is set.
Adds Cookie headers for the cookies in this collection to the given HTTP::Headers instance and returns it.
Adds Set-Cookie headers for the cookies in this collection to the given HTTP::Headers instance and returns it.
Clears the collection, removing all cookies.
Deletes and returns the HTTP::Cookie for the specified key, or returns nil if key cannot be found in the collection.
Yields each HTTP::Cookie in the collection.
Returns an iterator over the cookies of this collection.
Whether the collection contains any cookies.
Filling cookies by parsing the Cookie and Set-Cookie headers in the given HTTP::Headers.
Returns true if a cookie with the given key exists.
Returns the number of cookies contained in this collection.
Returns this collection as a plain Hash.
Enumerable(HTTP::Cookie)
Reference
Reference
Object
Object
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.
Creates a new empty instance.
Adds the given cookie to this collection, overrides an existing cookie with the same name if present.
response.cookies << HTTP::Cookie.new("foo", "bar", http_only: true) Gets the current HTTP::Cookie for the given key.
request.cookies["foo"].value # => "bar"
Sets a new cookie in the collection with a string value. This creates a never expiring, insecure, not HTTP only cookie with no explicit domain restriction and the path /.
require "http/client" request = HTTP::Request.new "GET", "/" request.cookies["foo"] = "bar"
Sets a new cookie in the collection to the given HTTP::Cookie instance. The name attribute must match the given key, else ArgumentError is raised.
require "http/client"
response = HTTP::Client::Response.new(200)
response.cookies["foo"] = HTTP::Cookie.new("foo", "bar", "/admin", Time.utc + 12.hours, secure: true) Gets the current HTTP::Cookie for the given key or nil if none is set.
require "http/client" request = HTTP::Request.new "GET", "/" request.cookies["foo"]? # => nil request.cookies["foo"] = "bar" request.cookies["foo"]?.try &.value # > "bar"
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.
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.
Clears the collection, removing all cookies.
Deletes and returns the HTTP::Cookie for the specified key, or returns nil if key cannot be found in the collection. Note that key should match the name attribute of the desired HTTP::Cookie.
Yields each HTTP::Cookie in the collection.
Returns an iterator over the cookies of this collection.
Whether the collection contains any cookies.
Filling cookies by parsing the Cookie and Set-Cookie headers in the given HTTP::Headers.
Returns true if a cookie with the given key exists.
request.cookies.has_key?("foo") # => true Returns the number of cookies contained in this collection.
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/HTTP/Cookies.html