Skip to content

Commit 316add8

Browse files
committed
Added ReadTimeoutSSL test
1 parent 79ce6f1 commit 316add8

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/test.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,50 @@ TEST(KeepAliveTest, ReadTimeout) {
29912991
ASSERT_FALSE(svr.is_running());
29922992
}
29932993

2994+
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
2995+
TEST(KeepAliveTest, ReadTimeoutSSL) {
2996+
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
2997+
ASSERT_TRUE(svr.is_valid());
2998+
2999+
svr.Get("/a", [&](const Request & /*req*/, Response &res) {
3000+
std::this_thread::sleep_for(std::chrono::seconds(2));
3001+
res.set_content("a", "text/plain");
3002+
});
3003+
3004+
svr.Get("/b", [&](const Request & /*req*/, Response &res) {
3005+
res.set_content("b", "text/plain");
3006+
});
3007+
3008+
auto listen_thread = std::thread([&svr]() {
3009+
svr.listen("localhost", PORT);
3010+
});
3011+
while (!svr.is_running()) {
3012+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
3013+
}
3014+
3015+
// Give GET time to get a few messages.
3016+
std::this_thread::sleep_for(std::chrono::seconds(1));
3017+
3018+
SSLClient cli("localhost", PORT);
3019+
cli.enable_server_certificate_verification(false);
3020+
cli.set_keep_alive(true);
3021+
cli.set_read_timeout(1);
3022+
3023+
auto resa = cli.Get("/a");
3024+
ASSERT_TRUE(!resa);
3025+
EXPECT_EQ(Error::Read, resa.error());
3026+
3027+
auto resb = cli.Get("/b");
3028+
ASSERT_TRUE(resb);
3029+
EXPECT_EQ(200, resb->status);
3030+
EXPECT_EQ("b", resb->body);
3031+
3032+
svr.stop();
3033+
listen_thread.join();
3034+
ASSERT_FALSE(svr.is_running());
3035+
}
3036+
#endif
3037+
29943038
class ServerTestWithAI_PASSIVE : public ::testing::Test {
29953039
protected:
29963040
ServerTestWithAI_PASSIVE()

0 commit comments

Comments
 (0)