mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
Merge pull request #447 from DoumanAsh/multiple_set_cookies
Correct setting cookies in HTTP2 writer
This commit is contained in:
commit
f4fba5f481
@ -151,6 +151,8 @@ impl<H: 'static> Writer for H2Writer<H> {
|
||||
.insert(CONTENT_ENCODING, HeaderValue::try_from(ce).unwrap());
|
||||
}
|
||||
|
||||
trace!("Response: {:?}", resp);
|
||||
|
||||
match self
|
||||
.respond
|
||||
.send_response(resp, self.flags.contains(Flags::EOF))
|
||||
@ -159,8 +161,6 @@ impl<H: 'static> Writer for H2Writer<H> {
|
||||
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "err")),
|
||||
}
|
||||
|
||||
trace!("HttpResponse: {:?}", msg);
|
||||
|
||||
let body = msg.replace_body(Body::Empty);
|
||||
if let Body::Binary(bytes) = body {
|
||||
if bytes.is_empty() {
|
||||
|
@ -931,3 +931,47 @@ fn test_application() {
|
||||
let response = srv.execute(request.send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_server_cookies() {
|
||||
use actix_web::http;
|
||||
|
||||
let mut srv = test::TestServer::with_factory(|| {
|
||||
App::new().resource("/", |r| r.f(|_| HttpResponse::Ok().cookie(http::CookieBuilder::new("first", "first_value").http_only(true).finish())
|
||||
.cookie(http::Cookie::new("second", "first_value"))
|
||||
.cookie(http::Cookie::new("second", "second_value"))
|
||||
.finish())
|
||||
)
|
||||
});
|
||||
|
||||
let first_cookie = http::CookieBuilder::new("first", "first_value").http_only(true).finish();
|
||||
let second_cookie = http::Cookie::new("second", "second_value");
|
||||
|
||||
let request = srv.get().finish().unwrap();
|
||||
let response = srv.execute(request.send()).unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let cookies = response.cookies().expect("To have cookies");
|
||||
assert_eq!(cookies.len(), 2);
|
||||
if cookies[0] == first_cookie {
|
||||
assert_eq!(cookies[1], second_cookie);
|
||||
} else {
|
||||
assert_eq!(cookies[0], second_cookie);
|
||||
assert_eq!(cookies[1], first_cookie);
|
||||
}
|
||||
|
||||
let first_cookie = first_cookie.to_string();
|
||||
let second_cookie = second_cookie.to_string();
|
||||
//Check that we have exactly two instances of raw cookie headers
|
||||
let cookies = response.headers().get_all(http::header::SET_COOKIE)
|
||||
.iter()
|
||||
.map(|header| header.to_str().expect("To str").to_string())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(cookies.len(), 2);
|
||||
if cookies[0] == first_cookie {
|
||||
assert_eq!(cookies[1], second_cookie);
|
||||
} else {
|
||||
assert_eq!(cookies[0], second_cookie);
|
||||
assert_eq!(cookies[1], first_cookie);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user