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