@@ -750,7 +750,7 @@ TEST(SpecifyServerIPAddressTest, AnotherHostname_Online) {
750750 auto host = " google.com" ;
751751 auto another_host = " example.com" ;
752752 auto wrong_ip = " 0.0.0.0" ;
753-
753+
754754#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
755755 SSLClient cli (host);
756756#else
@@ -766,7 +766,7 @@ TEST(SpecifyServerIPAddressTest, AnotherHostname_Online) {
766766TEST (SpecifyServerIPAddressTest, RealHostname_Online) {
767767 auto host = " google.com" ;
768768 auto wrong_ip = " 0.0.0.0" ;
769-
769+
770770#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
771771 SSLClient cli (host);
772772#else
@@ -1195,12 +1195,13 @@ TEST(ErrorHandlerTest, ContentLength) {
11951195TEST (ExceptionHandlerTest, ContentLength) {
11961196 Server svr;
11971197
1198- svr.set_exception_handler (
1199- [](const Request & /* req*/ , Response &res, std::exception & /* e*/ ) {
1200- res.status = 500 ;
1201- res.set_content (" abcdefghijklmnopqrstuvwxyz" ,
1202- " text/html" ); // <= Content-Length still 13
1203- });
1198+ svr.set_exception_handler ([](const Request & /* req*/ , Response &res,
1199+ std::exception &e) {
1200+ EXPECT_EQ (" abc" , std::string (e.what ()));
1201+ res.status = 500 ;
1202+ res.set_content (" abcdefghijklmnopqrstuvwxyz" ,
1203+ " text/html" ); // <= Content-Length still 13 at this point
1204+ });
12041205
12051206 svr.Get (" /hi" , [](const Request & /* req*/ , Response &res) {
12061207 res.set_content (" Hello World!\n " , " text/plain" );
@@ -1212,15 +1213,28 @@ TEST(ExceptionHandlerTest, ContentLength) {
12121213 // Give GET time to get a few messages.
12131214 std::this_thread::sleep_for (std::chrono::seconds (1 ));
12141215
1215- {
1216+ for ( size_t i = 0 ; i < 10 ; i++) {
12161217 Client cli (HOST, PORT);
12171218
1218- auto res = cli.Get (" /hi" );
1219- ASSERT_TRUE (res);
1220- EXPECT_EQ (500 , res->status );
1221- EXPECT_EQ (" text/html" , res->get_header_value (" Content-Type" ));
1222- EXPECT_EQ (" 26" , res->get_header_value (" Content-Length" ));
1223- EXPECT_EQ (" abcdefghijklmnopqrstuvwxyz" , res->body );
1219+ for (size_t j = 0 ; j < 100 ; j++) {
1220+ auto res = cli.Get (" /hi" );
1221+ ASSERT_TRUE (res);
1222+ EXPECT_EQ (500 , res->status );
1223+ EXPECT_EQ (" text/html" , res->get_header_value (" Content-Type" ));
1224+ EXPECT_EQ (" 26" , res->get_header_value (" Content-Length" ));
1225+ EXPECT_EQ (" abcdefghijklmnopqrstuvwxyz" , res->body );
1226+ }
1227+
1228+ cli.set_keep_alive (true );
1229+
1230+ for (size_t j = 0 ; j < 100 ; j++) {
1231+ auto res = cli.Get (" /hi" );
1232+ ASSERT_TRUE (res);
1233+ EXPECT_EQ (500 , res->status );
1234+ EXPECT_EQ (" text/html" , res->get_header_value (" Content-Type" ));
1235+ EXPECT_EQ (" 26" , res->get_header_value (" Content-Length" ));
1236+ EXPECT_EQ (" abcdefghijklmnopqrstuvwxyz" , res->body );
1237+ }
12241238 }
12251239
12261240 svr.stop ();
@@ -3625,10 +3639,11 @@ TEST(StreamingTest, NoContentLengthStreaming) {
36253639
36263640 auto get_thread = std::thread ([&client]() {
36273641 std::string s;
3628- auto res = client.Get (" /stream" , [&s](const char *data, size_t len) -> bool {
3629- s += std::string (data, len);
3630- return true ;
3631- });
3642+ auto res =
3643+ client.Get (" /stream" , [&s](const char *data, size_t len) -> bool {
3644+ s += std::string (data, len);
3645+ return true ;
3646+ });
36323647 EXPECT_EQ (" aaabbb" , s);
36333648 });
36343649
@@ -3766,7 +3781,7 @@ TEST(KeepAliveTest, Issue1041) {
37663781 res.set_content (" Hello World!" , " text/plain" );
37673782 });
37683783
3769- auto a2 = std::async (std::launch::async, [&svr]{ svr.listen (HOST, PORT); });
3784+ auto a2 = std::async (std::launch::async, [&svr] { svr.listen (HOST, PORT); });
37703785 std::this_thread::sleep_for (std::chrono::milliseconds (200 ));
37713786
37723787 Client cli (HOST, PORT);
0 commit comments