1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-26 19:41:12 +00: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 compression #103 and #104
* Fix client cookie support #101
* Enable compression support for `NamedFile` * Enable compression support for `NamedFile`
* Better support for `NamedFile` type * Better support for `NamedFile` type

View file

@ -292,13 +292,14 @@ impl ClientRequestBuilder {
/// # extern crate actix_web; /// # extern crate actix_web;
/// # use actix_web::*; /// # use actix_web::*;
/// # use actix_web::httpcodes::*; /// # use actix_web::httpcodes::*;
/// # use actix_web::client::*;
/// # /// #
/// use actix_web::header; /// use actix_web::header;
/// ///
/// fn main() { /// fn main() {
/// let req = ClientRequest::build() /// let req = ClientRequest::build()
/// .set(header::Date::now()) /// .set(header::Date::now())
/// .set(header::ContentType(mime::TEXT_HTML) /// .set(header::ContentType(mime::TEXT_HTML))
/// .finish().unwrap(); /// .finish().unwrap();
/// } /// }
/// ``` /// ```
@ -452,20 +453,6 @@ impl ClientRequestBuilder {
self 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. /// Do not add default request headers.
/// By default `Accept-Encoding` header is set. /// By default `Accept-Encoding` header is set.
pub fn no_default_headers(&mut self) -> &mut Self { pub fn no_default_headers(&mut self) -> &mut Self {
@ -559,8 +546,7 @@ impl ClientRequestBuilder {
if let Some(ref jar) = self.cookies { if let Some(ref jar) = self.cookies {
for cookie in jar.delta() { for cookie in jar.delta() {
request.headers.append( request.headers.append(
header::SET_COOKIE, header::COOKIE, HeaderValue::from_str(&cookie.to_string())?);
HeaderValue::from_str(&cookie.to_string())?);
} }
} }
request.body = body.into(); request.body = body.into();

View file

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