Skip to content

Commit 27310f9

Browse files
authored
Merge pull request #533 from kyrias/cookie-removal-documentation
Add warning about domain/path inconsistencies to remove_cookie doc
2 parents 62b828c + 208fddb commit 27310f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/response.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,24 @@ impl Response {
216216

217217
/// Removes the cookie. This instructs the `CookiesMiddleware` to send a cookie with empty value
218218
/// in the response.
219+
///
220+
/// ## Warning
221+
/// Take care when calling this function with a cookie that was returned by
222+
/// [`Request::cookie`](Request::cookie). As per [section 5.3 step 11 of RFC 6265], a new
223+
/// cookie is only treated as the same as an old one if it has a matching name, domain and
224+
/// path.
225+
///
226+
/// The domain and path are not sent to the server on subsequent HTTP requests, so if a cookie
227+
/// was originally set with a domain and/or path, calling this function on a cookie with the
228+
/// same name but with either a different, or no, domain and/or path will lead to us sending an
229+
/// empty cookie that the user agent will treat as unrelated to the original one, and will thus
230+
/// not remove the old one.
231+
///
232+
/// To avoid this you can manually set the [domain](Cookie::set_domain) and
233+
/// [path](Cookie::set_path) as necessary after retrieving the cookie using
234+
/// [`Request::cookie`](Request::cookie).
235+
///
236+
/// [section 5.3 step 11 of RFC 6265]: https://tools.ietf.org/html/rfc6265#section-5.3
219237
pub fn remove_cookie(&mut self, cookie: Cookie<'static>) {
220238
self.cookie_events.push(CookieEvent::Removed(cookie));
221239
}

0 commit comments

Comments
 (0)