@@ -889,6 +889,64 @@ TEST(UrlWithSpace, Redirect) {
889
889
EXPECT_EQ (200 , res->status );
890
890
EXPECT_EQ (18527 , res->get_header_value <uint64_t >(" Content-Length" ));
891
891
}
892
+
893
+ TEST (RedirectFromPageWithContent, Redirect) {
894
+ Server svr;
895
+
896
+ svr.Get (" /1" , [&](const Request & /* req*/ , Response &res) {
897
+ res.set_content (" ___" , " text/plain" );
898
+ res.set_redirect (" /2" );
899
+ });
900
+
901
+ svr.Get (" /2" , [&](const Request & /* req*/ , Response &res) {
902
+ res.set_content (" Hello World!" , " text/plain" );
903
+ });
904
+
905
+ auto th = std::thread ([&]() { svr.listen (" localhost" , PORT); });
906
+
907
+ while (!svr.is_running ()) {
908
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
909
+ }
910
+
911
+ // Give GET time to get a few messages.
912
+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
913
+
914
+ {
915
+ Client cli (" localhost" , PORT);
916
+ cli.set_follow_location (true );
917
+
918
+ std::string body;
919
+ auto res = cli.Get (" /1" ,
920
+ [&](const char *data, size_t data_length) {
921
+ body.append (data, data_length);
922
+ return true ;
923
+ });
924
+
925
+ ASSERT_TRUE (res);
926
+ EXPECT_EQ (200 , res->status );
927
+ EXPECT_EQ (" Hello World!" , body);
928
+ }
929
+
930
+ {
931
+ Client cli (" localhost" , PORT);
932
+
933
+ std::string body;
934
+ auto res = cli.Get (" /1" ,
935
+ [&](const char *data, size_t data_length) {
936
+ body.append (data, data_length);
937
+ return true ;
938
+ });
939
+
940
+ ASSERT_TRUE (res);
941
+ EXPECT_EQ (302 , res->status );
942
+ EXPECT_EQ (" ___" , body);
943
+ }
944
+
945
+ svr.stop ();
946
+ th.join ();
947
+ ASSERT_FALSE (svr.is_running ());
948
+ }
949
+
892
950
#endif
893
951
894
952
TEST (BindServerTest, BindDualStack) {
0 commit comments