mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
fix client cookie handling
This commit is contained in:
parent
1e5daa1de8
commit
9afad5885b
@ -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();
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user