pub struct CookieOptions {
pub max_age: Option<Duration>,
pub http_only: bool,
pub secure: bool,
pub same_site: SameSite,
pub path: String,
}Expand description
Configuration options for setting cookies.
The default options prioritize security:
http_only: true— prevents JavaScript accesssecure: true— HTTPS onlysame_site: Lax— CSRF protectionpath: "/"— available to all routes
§Example
ⓘ
use dioxus_cookie::{CookieOptions, SameSite};
use std::time::Duration;
let options = CookieOptions {
max_age: Some(Duration::from_secs(86400 * 7)), // 7 days
http_only: true,
secure: true,
same_site: SameSite::Strict,
path: "/".to_string(),
};Fields§
§max_age: Option<Duration>Cookie lifetime. None = session cookie (deleted when browser closes).
http_only: boolIf true, cookie is inaccessible to JavaScript/WASM. Default: true.
Always use true for session tokens to prevent XSS attacks.
secure: boolIf true, cookie is only sent over HTTPS. Default: true.
same_site: SameSiteCross-site request policy. Default: SameSite::Lax.
path: StringURL path scope for the cookie. Default: "/".
Implementations§
Source§impl CookieOptions
impl CookieOptions
Sourcepub fn build_header(&self, name: &str, value: &str) -> String
pub fn build_header(&self, name: &str, value: &str) -> String
Builds a Set-Cookie header string from the options.
The value is URL-encoded automatically.
Trait Implementations§
Source§impl Clone for CookieOptions
impl Clone for CookieOptions
Source§fn clone(&self) -> CookieOptions
fn clone(&self) -> CookieOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CookieOptions
impl Debug for CookieOptions
Auto Trait Implementations§
impl Freeze for CookieOptions
impl RefUnwindSafe for CookieOptions
impl Send for CookieOptions
impl Sync for CookieOptions
impl Unpin for CookieOptions
impl UnwindSafe for CookieOptions
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> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.