Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating a removal cookie via the builder #221

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<'c> CookieBuilder<'c> {
}

/// Makes the cookie being built 'permanent' by extending its expiration and
/// max age 20 years into the future.
/// max age 20 years into the future. See also [`Cookie::make_permanent()`].
///
/// # Example
///
Expand All @@ -233,6 +233,32 @@ impl<'c> CookieBuilder<'c> {
self
}

/// Makes the cookie being built 'removal' by clearing its value, setting a
/// max-age of `0`, and setting an expiration date far in the past. See also
/// [`Cookie::make_removal()`].
///
/// # Example
///
/// ```rust
/// # extern crate cookie;
/// use cookie::Cookie;
/// use cookie::time::Duration;
///
/// # fn main() {
/// let mut builder = Cookie::build("foo").removal();
/// assert_eq!(builder.inner().max_age(), Some(Duration::ZERO));
///
/// let mut builder = Cookie::build(("name", "value")).removal();
/// assert_eq!(builder.inner().value(), "");
/// assert_eq!(builder.inner().max_age(), Some(Duration::ZERO));
/// # }
/// ```
#[inline]
pub fn removal(mut self) -> Self {
self.cookie.make_removal();
self
}

/// Returns a borrow to the cookie currently being built.
///
/// # Example
Expand Down