Skip to content

Commit 3995ff0

Browse files
committed
Remove cookie APIs from Request & Response
1 parent 9a89aef commit 3995ff0

File tree

2 files changed

+1
-138
lines changed

2 files changed

+1
-138
lines changed

src/request.rs

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::headers::{
1212
};
1313
use crate::mime::Mime;
1414
use crate::trailers::{self, Trailers};
15-
use crate::Cookie;
1615
use crate::{Body, Method, TypeMap, Url, Version};
1716

1817
pin_project_lite::pin_project! {
@@ -363,74 +362,6 @@ impl Request {
363362
self.version = version;
364363
}
365364

366-
/// Get all cookies.
367-
///
368-
/// # Examples
369-
///
370-
/// ```
371-
/// # fn main() -> Result<(), http_types::Error> {
372-
/// #
373-
/// use http_types::{Cookie, Url, Method, Request, Version};
374-
///
375-
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
376-
/// req.set_cookie(Cookie::new("name", "value"));
377-
/// assert_eq!(req.cookies().unwrap(), vec![Cookie::new("name", "value")]);
378-
/// #
379-
/// # Ok(()) }
380-
/// ```
381-
pub fn cookies(&self) -> Result<Vec<Cookie<'_>>, crate::Error> {
382-
match self.header(&headers::COOKIE) {
383-
None => Ok(vec![]),
384-
Some(h) => h.iter().try_fold(vec![], |mut acc, h| {
385-
let cookie = Cookie::parse(h.as_str())?;
386-
acc.push(cookie);
387-
Ok(acc)
388-
}),
389-
}
390-
}
391-
392-
/// Get a cookie by name.
393-
///
394-
/// # Examples
395-
///
396-
/// ```
397-
/// # fn main() -> Result<(), http_types::Error> {
398-
/// #
399-
/// use http_types::{Cookie, Url, Method, Request, Version};
400-
///
401-
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
402-
/// req.set_cookie(Cookie::new("name", "value"));
403-
/// assert_eq!(req.cookie("name").unwrap(), Some(Cookie::new("name", "value")));
404-
/// #
405-
/// # Ok(()) }
406-
/// ```
407-
pub fn cookie(&self, name: &str) -> Result<Option<Cookie<'_>>, crate::Error> {
408-
let cookies = self.cookies()?;
409-
let cookie = cookies.into_iter().find(|c| c.name() == name);
410-
Ok(cookie)
411-
}
412-
413-
/// Set a cookie.
414-
///
415-
/// This will not override any existing cookies, and uses the `Cookies` header.
416-
///
417-
/// # Examples
418-
///
419-
/// ```
420-
/// # fn main() -> Result<(), http_types::Error> {
421-
/// #
422-
/// use http_types::{Cookie, Url, Method, Request, Version};
423-
///
424-
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
425-
/// req.set_cookie(Cookie::new("name", "value"));
426-
/// #
427-
/// # Ok(()) }
428-
/// ```
429-
pub fn set_cookie(&mut self, cookie: Cookie<'_>) {
430-
self.append_header(headers::COOKIE, HeaderValue::from(cookie))
431-
.unwrap();
432-
}
433-
434365
/// Sends trailers to the a receiver.
435366
pub fn send_trailers(&mut self) -> trailers::Sender {
436367
let sender = self

src/response.rs

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::headers::{
1212
};
1313
use crate::mime::Mime;
1414
use crate::trailers::{self, Trailers};
15-
use crate::{Body, Cookie, StatusCode, TypeMap, Version};
15+
use crate::{Body, StatusCode, TypeMap, Version};
1616

1717
pin_project_lite::pin_project! {
1818
/// An HTTP response.
@@ -328,74 +328,6 @@ impl Response {
328328
self.status = status;
329329
}
330330

331-
/// Get all cookies.
332-
///
333-
/// # Examples
334-
///
335-
/// ```
336-
/// # fn main() -> Result<(), http_types::Error> {
337-
/// #
338-
/// use http_types::{Cookie, Response, StatusCode, Version};
339-
///
340-
/// let mut res = Response::new(StatusCode::Ok);
341-
/// res.set_cookie(Cookie::new("name", "value"));
342-
/// assert_eq!(res.cookies().unwrap(), vec![Cookie::new("name", "value")]);
343-
/// #
344-
/// # Ok(()) }
345-
/// ```
346-
pub fn cookies(&self) -> Result<Vec<Cookie<'_>>, crate::Error> {
347-
match self.header(&headers::SET_COOKIE) {
348-
None => Ok(vec![]),
349-
Some(h) => h.iter().try_fold(vec![], |mut acc, h| {
350-
let cookie = Cookie::parse(h.as_str())?;
351-
acc.push(cookie);
352-
Ok(acc)
353-
}),
354-
}
355-
}
356-
357-
/// Get a cookie by name.
358-
///
359-
/// # Examples
360-
///
361-
/// ```
362-
/// # fn main() -> Result<(), http_types::Error> {
363-
/// #
364-
/// use http_types::{Cookie, Response, StatusCode, Version};
365-
///
366-
/// let mut res = Response::new(StatusCode::Ok);
367-
/// res.set_cookie(Cookie::new("name", "value"));
368-
/// assert_eq!(res.cookie("name").unwrap(), Some(Cookie::new("name", "value")));
369-
/// #
370-
/// # Ok(()) }
371-
/// ```
372-
pub fn cookie(&self, name: &str) -> Result<Option<Cookie<'_>>, crate::Error> {
373-
let cookies = self.cookies()?;
374-
let cookie = cookies.into_iter().find(|c| c.name() == name);
375-
Ok(cookie)
376-
}
377-
378-
/// Set a cookie.
379-
///
380-
/// This will not override any existing cookies, and uses the `Cookies` header.
381-
///
382-
/// # Examples
383-
///
384-
/// ```
385-
/// # fn main() -> Result<(), http_types::Error> {
386-
/// #
387-
/// use http_types::{Cookie, Response, StatusCode, Version};
388-
///
389-
/// let mut res = Response::new(StatusCode::Ok);
390-
/// res.set_cookie(Cookie::new("name", "value"));
391-
/// #
392-
/// # Ok(()) }
393-
/// ```
394-
pub fn set_cookie(&mut self, cookie: Cookie<'_>) {
395-
self.append_header(headers::SET_COOKIE, HeaderValue::from(cookie))
396-
.unwrap();
397-
}
398-
399331
/// Sends trailers to the a receiver.
400332
pub fn send_trailers(&mut self) -> trailers::Sender {
401333
let sender = self

0 commit comments

Comments
 (0)