1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

Fix client cookie support

This commit is contained in:
Nikolay Kim 2018-03-06 22:36:34 -08:00
parent acd33cccbb
commit c1419413aa
3 changed files with 7 additions and 19 deletions

View File

@ -4,6 +4,8 @@
* Fix compression #103 and #104
* Fix client cookie support #101
* Enable compression support for `NamedFile`
* Better support for `NamedFile` type

View File

@ -292,13 +292,14 @@ impl ClientRequestBuilder {
/// # extern crate actix_web;
/// # use actix_web::*;
/// # use actix_web::httpcodes::*;
/// # use actix_web::client::*;
/// #
/// use actix_web::header;
///
/// fn main() {
/// let req = ClientRequest::build()
/// .set(header::Date::now())
/// .set(header::ContentType(mime::TEXT_HTML)
/// .set(header::ContentType(mime::TEXT_HTML))
/// .finish().unwrap();
/// }
/// ```
@ -452,20 +453,6 @@ impl ClientRequestBuilder {
self
}
/// Remove cookie, cookie has to be cookie from `HttpRequest::cookies()` method.
pub fn del_cookie<'a>(&mut self, cookie: &Cookie<'a>) -> &mut Self {
{
if self.cookies.is_none() {
self.cookies = Some(CookieJar::new())
}
let jar = self.cookies.as_mut().unwrap();
let cookie = cookie.clone().into_owned();
jar.add_original(cookie.clone());
jar.remove(cookie);
}
self
}
/// Do not add default request headers.
/// By default `Accept-Encoding` header is set.
pub fn no_default_headers(&mut self) -> &mut Self {
@ -559,8 +546,7 @@ impl ClientRequestBuilder {
if let Some(ref jar) = self.cookies {
for cookie in jar.delta() {
request.headers.append(
header::SET_COOKIE,
HeaderValue::from_str(&cookie.to_string())?);
header::COOKIE, HeaderValue::from_str(&cookie.to_string())?);
}
}
request.body = body.into();

View File

@ -77,12 +77,12 @@ impl ClientResponse {
self.as_ref().status
}
/// Load request cookies.
/// Load response cookies.
pub fn cookies(&self) -> Result<&Vec<Cookie<'static>>, CookieParseError> {
if self.as_ref().cookies.is_none() {
let msg = self.as_mut();
let mut cookies = Vec::new();
if let Some(val) = msg.headers.get(header::COOKIE) {
if let Some(val) = msg.headers.get(header::SET_COOKIE) {
let s = str::from_utf8(val.as_bytes())
.map_err(CookieParseError::from)?;
for cookie in s.split("; ") {