mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-25 05:59:12 +00:00
Add KeepAliveTest.MaxCount
Some checks failed
test / ubuntu (64-bit) (push) Has been cancelled
test / macos (push) Has been cancelled
test / windows with SSL (push) Has been cancelled
test / windows without SSL (push) Has been cancelled
test / windows compiled (push) Has been cancelled
abidiff / abi (push) Has been cancelled
test / style-check (push) Has been cancelled
test / ubuntu (32-bit) (push) Has been cancelled
Some checks failed
test / ubuntu (64-bit) (push) Has been cancelled
test / macos (push) Has been cancelled
test / windows with SSL (push) Has been cancelled
test / windows without SSL (push) Has been cancelled
test / windows compiled (push) Has been cancelled
abidiff / abi (push) Has been cancelled
test / style-check (push) Has been cancelled
test / ubuntu (32-bit) (push) Has been cancelled
This commit is contained in:
parent
366eda72dc
commit
fd324e1412
1 changed files with 35 additions and 0 deletions
35
test/test.cc
35
test/test.cc
|
@ -5732,6 +5732,41 @@ TEST(KeepAliveTest, ReadTimeout) {
|
||||||
EXPECT_EQ("b", resb->body);
|
EXPECT_EQ("b", resb->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(KeepAliveTest, MaxCount) {
|
||||||
|
size_t keep_alive_max_count = 3;
|
||||||
|
|
||||||
|
Server svr;
|
||||||
|
svr.set_keep_alive_max_count(keep_alive_max_count);
|
||||||
|
|
||||||
|
svr.Get("/hi", [](const httplib::Request &, httplib::Response &res) {
|
||||||
|
res.set_content("Hello World!", "text/plain");
|
||||||
|
});
|
||||||
|
|
||||||
|
auto listen_thread = std::thread([&svr] { svr.listen(HOST, PORT); });
|
||||||
|
auto se = detail::scope_exit([&] {
|
||||||
|
svr.stop();
|
||||||
|
listen_thread.join();
|
||||||
|
ASSERT_FALSE(svr.is_running());
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.wait_until_ready();
|
||||||
|
|
||||||
|
Client cli(HOST, PORT);
|
||||||
|
cli.set_keep_alive(true);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 5; i++) {
|
||||||
|
auto result = cli.Get("/hi");
|
||||||
|
ASSERT_TRUE(result);
|
||||||
|
EXPECT_EQ(StatusCode::OK_200, result->status);
|
||||||
|
|
||||||
|
if (i == keep_alive_max_count - 1) {
|
||||||
|
EXPECT_EQ("close", result->get_header_value("Connection"));
|
||||||
|
} else {
|
||||||
|
EXPECT_FALSE(result->has_header("Connection"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(KeepAliveTest, Issue1041) {
|
TEST(KeepAliveTest, Issue1041) {
|
||||||
Server svr;
|
Server svr;
|
||||||
svr.set_keep_alive_timeout(3);
|
svr.set_keep_alive_timeout(3);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue