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"
Creates a new Cookie instance.
Returns true if this reference is the same as other.
Returns the expiration time of this cookie.
Expires the cookie.
Returns the expiration status of this cookie as a Bool.
Returns an unambiguous string representation of this cookie.
Sets the name of this cookie.
Returns true if this cookie has the Secure flag.
Returns a string representation of this cookie in the format used by the Cookie header of an HTTP request.
Returns a string representation of this cookie in the format used by the Cookie header of an HTTP request.
Returns a string representation of this cookie.
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.
Raises ArgumentError if self is not #valid?.
Sets the value of this cookie.
Reference
Reference
Reference
Object
Object
Object
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.
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 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 false if #name has a security prefix but the requirements are not met as per RFC 6265 bis §4.1.3, otherwise returns true.
Raises ArgumentError if self is not #valid?.
Sets the value of this cookie.
Raises IO::Error if the value is invalid as per RFC 6265 §4.1.1.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/HTTP/Cookie.html