use std::borrow::Cow;
use time::{Tm, Duration};
use ::{Cookie, SameSite};
#[derive(Debug, Clone)]
pub struct CookieBuilder {
cookie: Cookie<'static>,
}
impl CookieBuilder {
pub fn new<N, V>(name: N, value: V) -> CookieBuilder
where N: Into<Cow<'static, str>>,
V: Into<Cow<'static, str>>
{
CookieBuilder { cookie: Cookie::new(name, value) }
}
#[inline]
pub fn expires(mut self, when: Tm) -> CookieBuilder {
self.cookie.set_expires(when);
self
}
#[inline]
pub fn max_age(mut self, value: Duration) -> CookieBuilder {
self.cookie.set_max_age(value);
self
}
pub fn domain<D: Into<Cow<'static, str>>>(mut self, value: D) -> CookieBuilder {
self.cookie.set_domain(value);
self
}
pub fn path<P: Into<Cow<'static, str>>>(mut self, path: P) -> CookieBuilder {
self.cookie.set_path(path);
self
}
#[inline]
pub fn secure(mut self, value: bool) -> CookieBuilder {
self.cookie.set_secure(value);
self
}
#[inline]
pub fn http_only(mut self, value: bool) -> CookieBuilder {
self.cookie.set_http_only(value);
self
}
#[inline]
pub fn same_site(mut self, value: SameSite) -> CookieBuilder {
self.cookie.set_same_site(value);
self
}
#[inline]
pub fn permanent(mut self) -> CookieBuilder {
self.cookie.make_permanent();
self
}
#[inline]
pub fn finish(self) -> Cookie<'static> {
self.cookie
}
}