HTTP::Cookie
Represents a cookie with all its attributes. Provides convenient access and modification of them.
NOTE: To use Cookie, you must explicitly import it with require "http/cookie"
Constructors
Creates a new Cookie instance.
Raises IO::Error if name or value are invalid as per RFC 6265 §4.1.1.
Raises ArgumentError if name has a security prefix but the requirements are not met as per RFC 6265 bis §4.1.3.
Alternatively, if name has a security prefix, and the related properties are nil, the prefix will automatically be applied to the cookie.
Instance methods
Returns true if this reference is the same as other. Invokes same?.
Expires the cookie.
Causes the cookie to be destroyed. Sets the value to the empty string and expires its lifetime.
cookie = HTTP::Cookie.new("hello", "world")
cookie.expire
cookie.value # => ""
cookie.expired? # => true
Returns the expiration status of this cookie as a Bool.
time_reference can be passed to use a different reference time for
comparison. Default is the current time (Time.utc).
See Object#hash(hasher)
Returns an unambiguous string representation of this cookie.
It uses the Set-Cookie serialization from #to_set_cookie_header which
represents the full state of the cookie.
HTTP::Cookie.new("foo", "bar").inspect # => HTTP::Cookie["foo=bar"]
HTTP::Cookie.new("foo", "bar", domain: "example.com").inspect # => HTTP::Cookie["foo=bar; domain=example.com"]
Sets the name of this cookie.
Raises IO::Error if the value is invalid as per RFC 6265 §4.1.1.
Returns a string representation of this cookie in the format used by the
Cookie header of an HTTP request.
This includes only the #name and #value. All other attributes are left
out.
HTTP::Cookie.new("foo", "bar").to_cookie_header # => "foo=bar"
HTTP::Cookie.new("foo", "bar", domain: "example.com").to_cookie_header # => "foo=bar
Returns a string representation of this cookie in the format used by the
Cookie header of an HTTP request.
This includes only the #name and #value. All other attributes are left
out.
HTTP::Cookie.new("foo", "bar").to_cookie_header # => "foo=bar"
HTTP::Cookie.new("foo", "bar", domain: "example.com").to_cookie_header # => "foo=bar
Returns a string representation of this cookie.
It uses the Set-Cookie serialization from #to_set_cookie_header which
represents the full state of the cookie.
HTTP::Cookie.new("foo", "bar").to_s # => "foo=bar"
HTTP::Cookie.new("foo", "bar", domain: "example.com").to_s # => "foo=bar; domain=example.com"
Returns a string representation of this cookie in the format used by the
Set-Cookie header of an HTTP response.
HTTP::Cookie.new("foo", "bar").to_set_cookie_header # => "foo=bar"
HTTP::Cookie.new("foo", "bar", domain: "example.com").to_set_cookie_header # => "foo=bar; domain=example.com"
Returns a string representation of this cookie in the format used by the
Set-Cookie header of an HTTP response.
HTTP::Cookie.new("foo", "bar").to_set_cookie_header # => "foo=bar"
HTTP::Cookie.new("foo", "bar", domain: "example.com").to_set_cookie_header # => "foo=bar; domain=example.com"
Returns false if #name has a security prefix but the requirements are not met as per
RFC 6265 bis §4.1.3,
otherwise returns true.
Sets the value of this cookie.
Raises IO::Error if the value is invalid as per RFC 6265 §4.1.1.