@@ -839,6 +839,18 @@ TEST(HttpsToHttpRedirectTest3, Redirect) {
839
839
EXPECT_EQ (200 , res->status );
840
840
}
841
841
842
+ TEST (UrlWithSpace, Redirect) {
843
+ SSLClient cli (" edge.forgecdn.net" );
844
+ cli.set_follow_location (true );
845
+
846
+ auto res = cli.Get (" /files/2595/310/Neat 1.4-17.jar" );
847
+ ASSERT_TRUE (res);
848
+ EXPECT_EQ (200 , res->status );
849
+ EXPECT_EQ (18527 , res->get_header_value <uint64_t >(" Content-Length" ));
850
+ }
851
+
852
+ #endif
853
+
842
854
TEST (RedirectToDifferentPort, Redirect) {
843
855
Server svr8080;
844
856
Server svr8081;
@@ -878,16 +890,6 @@ TEST(RedirectToDifferentPort, Redirect) {
878
890
ASSERT_FALSE (svr8081.is_running ());
879
891
}
880
892
881
- TEST (UrlWithSpace, Redirect) {
882
- SSLClient cli (" edge.forgecdn.net" );
883
- cli.set_follow_location (true );
884
-
885
- auto res = cli.Get (" /files/2595/310/Neat 1.4-17.jar" );
886
- ASSERT_TRUE (res);
887
- EXPECT_EQ (200 , res->status );
888
- EXPECT_EQ (18527 , res->get_header_value <uint64_t >(" Content-Length" ));
889
- }
890
-
891
893
TEST (RedirectFromPageWithContent, Redirect) {
892
894
Server svr;
893
895
@@ -943,7 +945,61 @@ TEST(RedirectFromPageWithContent, Redirect) {
943
945
ASSERT_FALSE (svr.is_running ());
944
946
}
945
947
946
- #endif
948
+ TEST (RedirectFromPageWithContentIP6, Redirect) {
949
+ Server svr;
950
+
951
+ svr.Get (" /1" , [&](const Request & /* req*/ , Response &res) {
952
+ res.set_content (" ___" , " text/plain" );
953
+ // res.set_redirect("/2");
954
+ res.set_redirect (" http://[::1]:1234/2" );
955
+ });
956
+
957
+ svr.Get (" /2" , [&](const Request & /* req*/ , Response &res) {
958
+ res.set_content (" Hello World!" , " text/plain" );
959
+ });
960
+
961
+ auto th = std::thread ([&]() { svr.listen (" ::1" , 1234 ); });
962
+
963
+ while (!svr.is_running ()) {
964
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
965
+ }
966
+
967
+ // Give GET time to get a few messages.
968
+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
969
+
970
+ {
971
+ Client cli (" http://[::1]:1234" );
972
+ cli.set_follow_location (true );
973
+
974
+ std::string body;
975
+ auto res = cli.Get (" /1" , [&](const char *data, size_t data_length) {
976
+ body.append (data, data_length);
977
+ return true ;
978
+ });
979
+
980
+ ASSERT_TRUE (res);
981
+ EXPECT_EQ (200 , res->status );
982
+ EXPECT_EQ (" Hello World!" , body);
983
+ }
984
+
985
+ {
986
+ Client cli (" http://[::1]:1234" );
987
+
988
+ std::string body;
989
+ auto res = cli.Get (" /1" , [&](const char *data, size_t data_length) {
990
+ body.append (data, data_length);
991
+ return true ;
992
+ });
993
+
994
+ ASSERT_TRUE (res);
995
+ EXPECT_EQ (302 , res->status );
996
+ EXPECT_EQ (" ___" , body);
997
+ }
998
+
999
+ svr.stop ();
1000
+ th.join ();
1001
+ ASSERT_FALSE (svr.is_running ());
1002
+ }
947
1003
948
1004
TEST (PathUrlEncodeTest, PathUrlEncode) {
949
1005
Server svr;
@@ -2717,10 +2773,12 @@ TEST_F(ServerTest, PutLargeFileWithGzip) {
2717
2773
2718
2774
TEST_F (ServerTest, PutLargeFileWithGzip2) {
2719
2775
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
2720
- Client cli (" https://localhost:1234" );
2776
+ std::string s = std::string (" https://" ) + HOST + " :" + std::to_string (PORT);
2777
+ Client cli (s.c_str ());
2721
2778
cli.enable_server_certificate_verification (false );
2722
2779
#else
2723
- Client cli (" http://localhost:1234" );
2780
+ std::string s = std::string (" http://" ) + HOST + " :" + std::to_string (PORT);
2781
+ Client cli (s.c_str ());
2724
2782
#endif
2725
2783
cli.set_compress (true );
2726
2784
0 commit comments