class Marten::HTTP::Cookies
- Marten::HTTP::Cookies
- Reference
- Object
Overview
Represents a set of cookies.
Included Modules
- Enumerable({String, Array(String)})
Defined in:
marten/http/cookies.crmarten/http/cookies/sub_store/base.cr
marten/http/cookies/sub_store/encrypted.cr
marten/http/cookies/sub_store/signed.cr
Constructors
Instance Method Summary
-
#==(other : self)
Returns true if the other cookies object corresponds to the current cookies.
-
#[](name : String | Symbol)
Returns the value associated with the passed cookie name.
-
#[]=(name, value)
Allows to set a new cookie associated with the specified
name. -
#[]?(name : String | Symbol)
Returns the value associated with the passed cookie name or
nilif the cookie is not present. -
#delete(name : String | Symbol, path : String = "/", domain : String | Nil = nil, same_site : Nil | String | Symbol = nil) : String | Nil
Deletes a specific cookie and return its value, or
nilif the cookie does not exist. -
#each(&)
Must yield this collection's elements to the block.
-
#empty?(*args, **options)
Returns
trueif there are no cookies. -
#empty?(*args, **options, &)
Returns
trueif there are no cookies. -
#encrypted
Returns the encrypted cookies store.
-
#fetch(name : String | Symbol, default = nil)
Returns the value associated with the passed cookie name, or the passed
defaultif the cookie is not present. -
#fetch(name : String | Symbol, &)
Returns the value associated with the passed cookie name, or calls a block with the name when not found.
-
#has_key?(name : String | Symbol)
Returns
trueif the cookie with the provided name exists. -
#set(name : String | Symbol, value, expires : Time | Nil = nil, path : String = "/", domain : String | Nil = nil, secure : Bool = false, http_only : Bool = false, same_site : Nil | String | Symbol = nil) : Nil
Allows to set a new cookie.
-
#signed
Returns the signed cookies store.
-
#size(*args, **options)
Returns the number of cookies.
-
#size(*args, **options, &)
Returns the number of cookies.
Constructor Detail
Instance Method Detail
Allows to set a new cookie associated with the specified name.
The string representation of the passed value object will be used as the cookie value.
Returns the value associated with the passed cookie name or nil if the cookie is not present.
Deletes a specific cookie and return its value, or nil if the cookie does not exist.
Appart from the name of the cookie to delete, this method allows to define some additional cookie properties:
- the cookie
path - the associated
domain(useful in order to define cross-domain cookies) - the
same_sitepolicy (accepted values are"lax"or"strict")
The path, domain, and same_site values should always be the same that were used to create the cookie.
Otherwise the cookie might not be deleted properly.
Must yield this collection's elements to the block.
Returns the encrypted cookies store.
The returned object allows to set or fetch encrypted cookies. This means that whenever a cookie is requested from this store, the raw value of this cookie will be decrypted. This is useful to create cookies whose values can't be read nor tampered by users.
cookies.encrypted["foo"] = "bar"
cookies.encrypted["foo"] # => "bar"
Returns the value associated with the passed cookie name, or the passed default if the cookie is not present.
Returns the value associated with the passed cookie name, or calls a block with the name when not found.
Allows to set a new cookie.
The string representation of the passed value object will be used as the cookie value. Appart from the cookie
name and value, this method allows to define some additional cookie properties:
- the cookie expiry datetime (
expiresargument) - the cookie
path - the associated
domain(useful in order to define cross-domain cookies) - whether or not the cookie should be sent for HTTPS requests only (
secureargument) - whether or not client-side scripts should have access to the cookie (
http_onlyargument) - the
same_sitepolicy (accepted values are"lax"or"strict")
Returns the signed cookies store.
The returned object allows to set or fetch signed cookies. This means that whenever a cookie is requested from this store, the signed representation of the corresponding value will be verified. This is useful to create cookies that can't be tampered by users.
cookies.signed["foo"] = "bar"
cookies.signed["foo"] # => "bar"