1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-18 22:26:37 +00:00

Correct settings headers for HTTP2

Add test to verify number of Set-Cookies
This commit is contained in:
Douman 2018-08-04 01:34:23 +03:00
parent 84b27db218
commit 900fd5a98e
2 changed files with 47 additions and 3 deletions

View file

@ -112,7 +112,7 @@ impl<H: 'static> Writer for H2Writer<H> {
DATE => has_date = true,
_ => (),
}
resp.headers_mut().insert(key, value.clone());
resp.headers_mut().append(key, value.clone());
}
// set date header
@ -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!("Response: {:?}", msg);
let body = msg.replace_body(Body::Empty);
if let Body::Binary(bytes) = body {
if bytes.is_empty() {

View file

@ -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);
}
}