1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-04 07:16:38 +00:00

fix client cookie handling

This commit is contained in:
Alex Whitney 2018-03-07 09:48:34 +00:00
parent 1e5daa1de8
commit 9afad5885b
2 changed files with 16 additions and 6 deletions

View file

@ -544,9 +544,21 @@ impl ClientRequestBuilder {
// set cookies // set cookies
if let Some(ref jar) = self.cookies { if let Some(ref jar) = self.cookies {
for cookie in jar.delta() { let ncookies = jar.iter().count();
if ncookies > 0 {
let mut payload = String::new();
for (ix, cookie) in jar.iter().enumerate() {
payload.push_str(&cookie.name());
payload.push('=');
payload.push_str(&cookie.value());
// semi-colon delimited, except for final k-v pair
if ix < ncookies - 1 {
payload.push(';');
payload.push(' ');
}
}
request.headers.append( request.headers.append(
header::COOKIE, HeaderValue::from_str(&cookie.to_string())?); header::COOKIE, HeaderValue::from_str(&payload)?);
} }
} }
request.body = body.into(); request.body = body.into();

View file

@ -82,12 +82,10 @@ impl ClientResponse {
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::SET_COOKIE) { for val in msg.headers.get_all(header::SET_COOKIE).iter() {
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("; ") { cookies.push(Cookie::parse_encoded(s)?.into_owned());
cookies.push(Cookie::parse_encoded(cookie)?.into_owned());
}
} }
msg.cookies = Some(cookies) msg.cookies = Some(cookies)
} }