Skip to content

Commit ddecb26

Browse files
committed
fix(http): no longer keep alive for Http1.0 if no Connection header
Closes #596
1 parent 7c2e512 commit ddecb26

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/http/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,25 @@ pub struct RawStatus(pub u16, pub Cow<'static, str>);
2222
pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool {
2323
trace!("should_keep_alive( {:?}, {:?} )", version, headers.get::<Connection>());
2424
match (version, headers.get::<Connection>()) {
25+
(Http10, None) => false,
2526
(Http10, Some(conn)) if !conn.contains(&KeepAlive) => false,
2627
(Http11, Some(conn)) if conn.contains(&Close) => false,
2728
_ => true
2829
}
2930
}
31+
32+
#[test]
33+
fn test_should_keep_alive() {
34+
let mut headers = Headers::new();
35+
36+
assert!(!should_keep_alive(Http10, &headers));
37+
assert!(should_keep_alive(Http11, &headers));
38+
39+
headers.set(Connection::close());
40+
assert!(!should_keep_alive(Http10, &headers));
41+
assert!(!should_keep_alive(Http11, &headers));
42+
43+
headers.set(Connection::keep_alive());
44+
assert!(should_keep_alive(Http10, &headers));
45+
assert!(should_keep_alive(Http11, &headers));
46+
}

0 commit comments

Comments
 (0)