Skip to content

Commit

Permalink
fix(http): no longer keep alive for Http1.0 if no Connection header
Browse files Browse the repository at this point in the history
Closes #596
  • Loading branch information
seanmonstar committed Jul 6, 2015
1 parent 7c2e512 commit ddecb26
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,25 @@ pub struct RawStatus(pub u16, pub Cow<'static, str>);
pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool {
trace!("should_keep_alive( {:?}, {:?} )", version, headers.get::<Connection>());
match (version, headers.get::<Connection>()) {
(Http10, None) => false,
(Http10, Some(conn)) if !conn.contains(&KeepAlive) => false,
(Http11, Some(conn)) if conn.contains(&Close) => false,
_ => true
}
}

#[test]
fn test_should_keep_alive() {
let mut headers = Headers::new();

assert!(!should_keep_alive(Http10, &headers));
assert!(should_keep_alive(Http11, &headers));

headers.set(Connection::close());
assert!(!should_keep_alive(Http10, &headers));
assert!(!should_keep_alive(Http11, &headers));

headers.set(Connection::keep_alive());
assert!(should_keep_alive(Http10, &headers));
assert!(should_keep_alive(Http11, &headers));
}

0 comments on commit ddecb26

Please sign in to comment.