From ddecb262b39b90e594a95ba16c4dc8085930677e Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 6 Jul 2015 12:55:25 -0700 Subject: [PATCH] fix(http): no longer keep alive for Http1.0 if no Connection header Closes #596 --- src/http/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/http/mod.rs b/src/http/mod.rs index e997f7c5cd..a52f2023ec 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -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::()); match (version, headers.get::()) { + (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)); +}