pub struct Cookie { /* private fields */ }Expand description
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
Create a new cookie with the given name and value
Default options:
- HttpOnly: true
- Secure: true
- SameSite: Lax
- Path: “/”
Sourcepub fn http_only(self, value: bool) -> Self
pub fn http_only(self, value: bool) -> Self
Set the HttpOnly flag (default: true)
HttpOnly cookies are not accessible via JavaScript, protecting against XSS.
Sourcepub fn secure(self, value: bool) -> Self
pub fn secure(self, value: bool) -> Self
Set the Secure flag (default: true)
Secure cookies are only sent over HTTPS connections.
Sourcepub fn same_site(self, value: SameSite) -> Self
pub fn same_site(self, value: SameSite) -> Self
Set the SameSite attribute (default: Lax)
Controls when the cookie is sent with cross-site requests.
Sourcepub fn max_age(self, duration: Duration) -> Self
pub fn max_age(self, duration: Duration) -> Self
Set the cookie’s max age
The cookie will expire after this duration.
Sourcepub fn to_header_value(&self) -> String
pub fn to_header_value(&self) -> String
Build the Set-Cookie header value
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cookie
impl RefUnwindSafe for Cookie
impl Send for Cookie
impl Sync for Cookie
impl Unpin for Cookie
impl UnsafeUnpin for Cookie
impl UnwindSafe for Cookie
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more