Struct isahc::cookies::CookieBuilder
source · pub struct CookieBuilder { /* private fields */ }
cookies
only.Expand description
Builder for a Cookie
.
use isahc::cookies::Cookie;
use std::time::{Duration, SystemTime};
let cookie: Cookie = Cookie::builder("name", "value") // or CookieBuilder::new("name", "value")
.domain("example.com")
.path("/")
.secure(true)
.expiration(SystemTime::now() + Duration::from_secs(30 * 60))
.build()
.unwrap();
Implementations
sourceimpl CookieBuilder
impl CookieBuilder
sourcepub fn new<N, V>(name: N, value: V) -> Selfwhere
N: Into<String>,
V: Into<String>,
pub fn new<N, V>(name: N, value: V) -> Selfwhere
N: Into<String>,
V: Into<String>,
Create a new cookie builder with a given name and value.
sourcepub fn domain<S>(self, domain: S) -> Selfwhere
S: Into<String>,
pub fn domain<S>(self, domain: S) -> Selfwhere
S: Into<String>,
Sets the domain the cookie belongs to.
Note that the domain will be preserved exactly as supplied. If the
string has a .
prefix that should be ignored (such as allowed by the
Set-Cookie
HTTP header), then you must remove it manually first.
sourcepub fn path<S>(self, path: S) -> Selfwhere
S: Into<String>,
pub fn path<S>(self, path: S) -> Selfwhere
S: Into<String>,
Sets the path prefix that this cookie belongs to.
sourcepub fn secure(self, secure: bool) -> Self
pub fn secure(self, secure: bool) -> Self
True if the cookie is marked as secure (limited in scope to HTTPS).
sourcepub fn expiration<T>(self, expiration: T) -> Selfwhere
T: Into<SystemTime>,
pub fn expiration<T>(self, expiration: T) -> Selfwhere
T: Into<SystemTime>,
Time when this cookie expires. If not present, then this is a session cookie that expires when the current client session ends.
sourcepub fn build(self) -> Result<Cookie, ParseError>
pub fn build(self) -> Result<Cookie, ParseError>
Builds the cookie.
Returns an error if either the name or value given contains illegal characters. In practice, only a subset of US-ASCII characters are allowed in cookies for maximum compatibility with most web servers.
Trait Implementations
sourceimpl Clone for CookieBuilder
impl Clone for CookieBuilder
sourcefn clone(&self) -> CookieBuilder
fn clone(&self) -> CookieBuilder
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more