1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-28 01:52:57 +01: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
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(
header::COOKIE, HeaderValue::from_str(&cookie.to_string())?);
header::COOKIE, HeaderValue::from_str(&payload)?);
}
}
request.body = body.into();

View File

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