mirror of
https://github.com/actix/actix-web.git
synced 2024-09-09 05:08:32 +00:00
Correct settings headers for HTTP2
Add test to verify number of Set-Cookies
This commit is contained in:
parent
84b27db218
commit
900fd5a98e
2 changed files with 47 additions and 3 deletions
|
@ -112,7 +112,7 @@ impl<H: 'static> Writer for H2Writer<H> {
|
||||||
DATE => has_date = true,
|
DATE => has_date = true,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
resp.headers_mut().insert(key, value.clone());
|
resp.headers_mut().append(key, value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// set date header
|
// set date header
|
||||||
|
@ -151,6 +151,8 @@ impl<H: 'static> Writer for H2Writer<H> {
|
||||||
.insert(CONTENT_ENCODING, HeaderValue::try_from(ce).unwrap());
|
.insert(CONTENT_ENCODING, HeaderValue::try_from(ce).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trace!("Response: {:?}", resp);
|
||||||
|
|
||||||
match self
|
match self
|
||||||
.respond
|
.respond
|
||||||
.send_response(resp, self.flags.contains(Flags::EOF))
|
.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")),
|
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "err")),
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!("Response: {:?}", msg);
|
|
||||||
|
|
||||||
let body = msg.replace_body(Body::Empty);
|
let body = msg.replace_body(Body::Empty);
|
||||||
if let Body::Binary(bytes) = body {
|
if let Body::Binary(bytes) = body {
|
||||||
if bytes.is_empty() {
|
if bytes.is_empty() {
|
||||||
|
|
|
@ -931,3 +931,47 @@ fn test_application() {
|
||||||
let response = srv.execute(request.send()).unwrap();
|
let response = srv.execute(request.send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
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 a new issue