Code cleanup

This commit is contained in:
yhirose 2023-03-03 22:41:57 -05:00
parent bab5c0e907
commit cdaa5c48db
2 changed files with 8 additions and 10 deletions

View file

@ -6309,7 +6309,7 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) {
if (is_ssl()) { if (is_ssl()) {
auto &scli = static_cast<SSLClient &>(*this); auto &scli = static_cast<SSLClient &>(*this);
if (!proxy_host_.empty() && proxy_port_ != -1) { if (!proxy_host_.empty() && proxy_port_ != -1) {
bool success = false; auto success = false;
if (!scli.connect_with_proxy(socket_, res, success, error)) { if (!scli.connect_with_proxy(socket_, res, success, error)) {
return success; return success;
} }
@ -7789,7 +7789,7 @@ inline bool SSLServer::process_and_close_socket(socket_t sock) {
}, },
[](SSL * /*ssl2*/) { return true; }); [](SSL * /*ssl2*/) { return true; });
bool ret = false; auto ret = false;
if (ssl) { if (ssl) {
ret = detail::process_server_socket_ssl( ret = detail::process_server_socket_ssl(
svr_sock_, ssl, sock, keep_alive_max_count_, keep_alive_timeout_sec_, svr_sock_, ssl, sock, keep_alive_max_count_, keep_alive_timeout_sec_,

View file

@ -4026,7 +4026,7 @@ TEST(KeepAliveTest, ReadTimeout) {
cli.set_read_timeout(std::chrono::seconds(1)); cli.set_read_timeout(std::chrono::seconds(1));
auto resa = cli.Get("/a"); auto resa = cli.Get("/a");
ASSERT_TRUE(!resa); ASSERT_FALSE(resa);
EXPECT_EQ(Error::Read, resa.error()); EXPECT_EQ(Error::Read, resa.error());
auto resb = cli.Get("/b"); auto resb = cli.Get("/b");
@ -4040,33 +4040,31 @@ TEST(KeepAliveTest, ReadTimeout) {
} }
TEST(KeepAliveTest, Issue1041) { TEST(KeepAliveTest, Issue1041) {
const auto resourcePath = "/hi";
Server svr; Server svr;
svr.set_keep_alive_timeout(3); svr.set_keep_alive_timeout(3);
svr.Get(resourcePath, [](const httplib::Request &, httplib::Response &res) { svr.Get("/hi", [](const httplib::Request &, httplib::Response &res) {
res.set_content("Hello World!", "text/plain"); res.set_content("Hello World!", "text/plain");
}); });
auto a2 = std::async(std::launch::async, [&svr] { svr.listen(HOST, PORT); }); auto f = std::async(std::launch::async, [&svr] { svr.listen(HOST, PORT); });
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
Client cli(HOST, PORT); Client cli(HOST, PORT);
cli.set_keep_alive(true); cli.set_keep_alive(true);
auto result = cli.Get(resourcePath); auto result = cli.Get("/hi");
ASSERT_TRUE(result); ASSERT_TRUE(result);
EXPECT_EQ(200, result->status); EXPECT_EQ(200, result->status);
std::this_thread::sleep_for(std::chrono::seconds(5)); std::this_thread::sleep_for(std::chrono::seconds(5));
result = cli.Get(resourcePath); result = cli.Get("/hi");
ASSERT_TRUE(result); ASSERT_TRUE(result);
EXPECT_EQ(200, result->status); EXPECT_EQ(200, result->status);
svr.stop(); svr.stop();
a2.wait(); f.wait();
} }
TEST(ClientProblemDetectionTest, ContentProvider) { TEST(ClientProblemDetectionTest, ContentProvider) {