pub struct Attributes<'c> { /* private fields */ }Expand description
Simple builder for cookie attributes
Attributes acts as a facade to ResponseCookie and RemovalCoolie
use cookiebox::cookiebox_macros::cookie;
use cookiebox::cookies::{CookieName, OutgoingConfig};
use cookiebox::{Attributes, SameSite, Expiration};
use cookiebox::time::{Date, Duration, Month, OffsetDateTime, Time};
#[cookie(name = "my-cookie")]
pub struct MyCookie;
impl OutgoingConfig for MyCookie {
type Insert = String;
fn attributes<'c>() -> Attributes<'c> {
let date = Date::from_calendar_date(2024, Month::January, 1).unwrap();
let time = Time::from_hms(0, 0, 0).unwrap();
let date = OffsetDateTime::new_utc(date, time);
Attributes::new()
.path("/some-path")
// the leading dot is stripped
.domain("..example.com")
.same_site(SameSite::Lax)
.secure(true)
.http_only(true)
.partitioned(true)
.expires(Expiration::from(date))
// max_age take precedence over expires
.max_age(Duration::hours(10))
// This sets max_age and expires to 20 years in the future
.permanent(true)
}
}Implementations§
Source§impl<'c> Attributes<'c>
impl<'c> Attributes<'c>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Attributes
Sourcepub fn domain<T: Into<Cow<'c, str>>>(self, domain: T) -> Self
pub fn domain<T: Into<Cow<'c, str>>>(self, domain: T) -> Self
Sets the domain of self to domain
Note: if the Domain starts with a leading ., the leading . is stripped.
Sourcepub fn http_only<T: Into<Option<bool>>>(self, value: T) -> Self
pub fn http_only<T: Into<Option<bool>>>(self, value: T) -> Self
Sets the http_only of self to value
Sourcepub fn same_site<T: Into<Option<SameSite>>>(self, value: T) -> Self
pub fn same_site<T: Into<Option<SameSite>>>(self, value: T) -> Self
Sets the same_site of self to value
Note: If SameSite attribute is set to None, the Secure flag will be set automatically , unless explicitly set to false.
Sourcepub fn max_age<T: Into<Option<Duration>>>(self, value: T) -> Self
pub fn max_age<T: Into<Option<Duration>>>(self, value: T) -> Self
Sets the max_age of self to value
Sourcepub fn expires<T: Into<Option<Expiration>>>(self, value: T) -> Self
pub fn expires<T: Into<Option<Expiration>>>(self, value: T) -> Self
Sets the expires of self to value
Sourcepub fn partitioned<T: Into<Option<bool>>>(self, value: T) -> Self
pub fn partitioned<T: Into<Option<bool>>>(self, value: T) -> Self
Sets the partitioned of self to value
Note: Partitioned cookies require the Secure attribute. If not set explicitly, the browser will automatically set it to true.
Trait Implementations§
Source§impl Default for Attributes<'_>
impl Default for Attributes<'_>
Create Attributes with default values - path: "/", SameSite: Lax, and http_only: true
Auto Trait Implementations§
impl<'c> Freeze for Attributes<'c>
impl<'c> RefUnwindSafe for Attributes<'c>
impl<'c> Send for Attributes<'c>
impl<'c> Sync for Attributes<'c>
impl<'c> Unpin for Attributes<'c>
impl<'c> UnwindSafe for Attributes<'c>
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