Skip to content

Commit

Permalink
Add 'CookieBuilder::removal()'.
Browse files Browse the repository at this point in the history
Add a `removal()` method to `CookieBuilder`, a counterpart to
`Cookie::make_removal()`, analogous to `CookieBuilder::permanent()`,
counterpart to `Cookie::make_permanent()`.
  • Loading branch information
jedenastka authored and SergioBenitez committed Jan 23, 2024
1 parent 273e397 commit fa37205
Showing 1 changed file with 27 additions and 1 deletion.
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

0 comments on commit fa37205

Please sign in to comment.