use http::{Request, Response, Version};
use crate::CloseReason;
use super::scenario::Scenario;
#[test]
fn http10_with_keep_alive() {
let scenario = Scenario::builder()
.request(
Request::get("/path")
.version(Version::HTTP_10)
.header("connection", "keep-alive")
.body(())
.unwrap(),
)
.response(
Response::builder()
.status(200)
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(!reply.must_close_connection());
}
#[test]
fn reuse_connection() {
let scenario = Scenario::builder()
.get("/path")
.response(
Response::builder()
.status(200)
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(!reply.must_close_connection());
}
#[test]
fn close_due_to_client_connection_close() {
let scenario = Scenario::builder()
.request(
Request::get("/path")
.header("connection", "close")
.body(())
.unwrap(),
)
.response(
Response::builder()
.status(200)
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(reply.must_close_connection());
let inner = reply.inner();
assert_eq!(
*inner.close_reason.first().unwrap(),
CloseReason::ClientConnectionClose
);
}
#[test]
fn close_due_to_server_connection_close() {
let scenario = Scenario::builder()
.get("/path")
.response(
Response::builder()
.status(200)
.header("connection", "close")
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(reply.must_close_connection());
let inner = reply.inner();
assert_eq!(
*inner.close_reason.first().unwrap(),
CloseReason::ServerConnectionClose
);
}
#[test]
fn close_due_to_http10() {
let scenario = Scenario::builder()
.request(
Request::get("/path")
.version(Version::HTTP_10)
.body(())
.unwrap(),
)
.response(
Response::builder()
.status(200)
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(reply.must_close_connection());
let inner = reply.inner();
assert_eq!(
*inner.close_reason.first().unwrap(),
CloseReason::CloseDelimitedBody
);
}
#[test]
fn close_due_to_client_connection_close_capitalized() {
let scenario = Scenario::builder()
.request(
Request::get("/path")
.header("connection", "Close")
.body(())
.unwrap(),
)
.response(
Response::builder()
.status(200)
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(reply.must_close_connection());
let inner = reply.inner();
assert!(
inner
.close_reason
.contains(&CloseReason::ClientConnectionClose)
);
}
#[test]
fn close_due_to_client_connection_close_in_list() {
let scenario = Scenario::builder()
.request(
Request::get("/path")
.header("connection", "keep-alive, close")
.body(())
.unwrap(),
)
.response(
Response::builder()
.status(200)
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(reply.must_close_connection());
let inner = reply.inner();
assert!(
inner
.close_reason
.contains(&CloseReason::ClientConnectionClose)
);
}
#[test]
fn http10_with_keep_alive_capitalized() {
let scenario = Scenario::builder()
.request(
Request::get("/path")
.version(Version::HTTP_10)
.header("connection", "Keep-Alive")
.body(())
.unwrap(),
)
.response(
Response::builder()
.status(200)
.header("content-length", "0")
.body(())
.unwrap(),
)
.build();
let reply = scenario.to_cleanup();
assert!(!reply.must_close_connection());
}