pub struct Cookie { /* private fields */ }Expand description
A cookie to send, or one that arrived.
Implementations§
Source§impl Cookie
impl Cookie
Sourcepub fn new(name: impl Into<String>, value: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self
A cookie with sensible defaults: path /, HttpOnly, SameSite=Lax.
Those defaults are the safe ones rather than the empty ones. A cookie
this framework sets is a session or CSRF cookie until proven otherwise,
and both want to be invisible to scripts and not sent cross-site. Opt
out explicitly with http_only(false).
Sourcepub fn removal(name: impl Into<String>) -> Self
pub fn removal(name: impl Into<String>) -> Self
A cookie that instructs the browser to delete the named one.
Sourcepub fn domain(self, domain: impl Into<String>) -> Self
pub fn domain(self, domain: impl Into<String>) -> Self
Scope the cookie to a domain (and its subdomains).
Sourcepub fn max_age(self, seconds: i64) -> Self
pub fn max_age(self, seconds: i64) -> Self
Expire the cookie after seconds. 0 deletes it immediately.
Sourcepub fn http_only(self, http_only: bool) -> Self
pub fn http_only(self, http_only: bool) -> Self
Hide the cookie from JavaScript. On by default.
Sourcepub fn same_site(self, same_site: SameSite) -> Self
pub fn same_site(self, same_site: SameSite) -> Self
Set the cross-site policy.
SameSite::None also forces Secure, because every current browser
rejects SameSite=None without it — silently, which would be a
miserable thing to debug.
Render the Set-Cookie header value.