@@ -652,8 +652,9 @@ TEST(BaseAuthTest, FromHTTPWatch) {
652
652
}
653
653
654
654
{
655
- auto res = cli.Get (" /basic-auth/hello/world" ,
656
- {make_basic_authentication_header (" hello" , " world" )});
655
+ auto res =
656
+ cli.Get (" /basic-auth/hello/world" ,
657
+ Headers{make_basic_authentication_header (" hello" , " world" )});
657
658
ASSERT_TRUE (res);
658
659
EXPECT_EQ (" {\n \" authenticated\" : true, \n \" user\" : \" hello\"\n }\n " ,
659
660
res->body );
@@ -816,6 +817,31 @@ TEST(HttpsToHttpRedirectTest, Redirect) {
816
817
EXPECT_EQ (200 , res->status );
817
818
}
818
819
820
+ TEST (HttpsToHttpRedirectTest2, Redirect) {
821
+ SSLClient cli (" nghttp2.org" );
822
+ cli.set_follow_location (true );
823
+
824
+ Params params;
825
+ params.emplace (" url" , " http://www.google.com" );
826
+ params.emplace (" status_code" , " 302" );
827
+
828
+ auto res = cli.Get (" /httpbin/redirect-to" , params);
829
+ ASSERT_TRUE (res);
830
+ EXPECT_EQ (200 , res->status );
831
+ }
832
+
833
+ TEST (HttpsToHttpRedirectTest3, Redirect) {
834
+ SSLClient cli (" nghttp2.org" );
835
+ cli.set_follow_location (true );
836
+
837
+ Params params;
838
+ params.emplace (" url" , " http://www.google.com" );
839
+
840
+ auto res = cli.Get (" /httpbin/redirect-to?status_code=302" , params);
841
+ ASSERT_TRUE (res);
842
+ EXPECT_EQ (200 , res->status );
843
+ }
844
+
819
845
TEST (RedirectToDifferentPort, Redirect) {
820
846
Server svr8080;
821
847
Server svr8081;
@@ -956,9 +982,8 @@ TEST(ErrorHandlerTest, ContentLength) {
956
982
TEST (NoContentTest, ContentLength) {
957
983
Server svr;
958
984
959
- svr.Get (" /hi" , [](const Request & /* req*/ , Response &res) {
960
- res.status = 204 ;
961
- });
985
+ svr.Get (" /hi" ,
986
+ [](const Request & /* req*/ , Response &res) { res.status = 204 ; });
962
987
auto thread = std::thread ([&]() { svr.listen (HOST, PORT); });
963
988
964
989
// Give GET time to get a few messages.
@@ -1853,7 +1878,8 @@ TEST_F(ServerTest, UserDefinedMIMETypeMapping) {
1853
1878
}
1854
1879
1855
1880
TEST_F (ServerTest, StaticFileRange) {
1856
- auto res = cli_.Get (" /dir/test.abcde" , {{make_range_header ({{2 , 3 }})}});
1881
+ auto res =
1882
+ cli_.Get (" /dir/test.abcde" , Headers{{make_range_header ({{2 , 3 }})}});
1857
1883
ASSERT_TRUE (res);
1858
1884
EXPECT_EQ (206 , res->status );
1859
1885
EXPECT_EQ (" text/abcde" , res->get_header_value (" Content-Type" ));
@@ -2156,7 +2182,7 @@ TEST_F(ServerTest, CaseInsensitiveTransferEncoding) {
2156
2182
}
2157
2183
2158
2184
TEST_F (ServerTest, GetStreamed2) {
2159
- auto res = cli_.Get (" /streamed" , {{make_range_header ({{2 , 3 }})}});
2185
+ auto res = cli_.Get (" /streamed" , Headers {{make_range_header ({{2 , 3 }})}});
2160
2186
ASSERT_TRUE (res);
2161
2187
EXPECT_EQ (206 , res->status );
2162
2188
EXPECT_EQ (" 2" , res->get_header_value (" Content-Length" ));
@@ -2172,7 +2198,8 @@ TEST_F(ServerTest, GetStreamed) {
2172
2198
}
2173
2199
2174
2200
TEST_F (ServerTest, GetStreamedWithRange1) {
2175
- auto res = cli_.Get (" /streamed-with-range" , {{make_range_header ({{3 , 5 }})}});
2201
+ auto res =
2202
+ cli_.Get (" /streamed-with-range" , Headers{{make_range_header ({{3 , 5 }})}});
2176
2203
ASSERT_TRUE (res);
2177
2204
EXPECT_EQ (206 , res->status );
2178
2205
EXPECT_EQ (" 3" , res->get_header_value (" Content-Length" ));
@@ -2181,7 +2208,8 @@ TEST_F(ServerTest, GetStreamedWithRange1) {
2181
2208
}
2182
2209
2183
2210
TEST_F (ServerTest, GetStreamedWithRange2) {
2184
- auto res = cli_.Get (" /streamed-with-range" , {{make_range_header ({{1 , -1 }})}});
2211
+ auto res =
2212
+ cli_.Get (" /streamed-with-range" , Headers{{make_range_header ({{1 , -1 }})}});
2185
2213
ASSERT_TRUE (res);
2186
2214
EXPECT_EQ (206 , res->status );
2187
2215
EXPECT_EQ (" 6" , res->get_header_value (" Content-Length" ));
@@ -2190,7 +2218,7 @@ TEST_F(ServerTest, GetStreamedWithRange2) {
2190
2218
}
2191
2219
2192
2220
TEST_F (ServerTest, GetStreamedWithRangeSuffix1) {
2193
- auto res = cli_.Get (" /streamed-with-range" , {{" Range" , " bytes=-3" }});
2221
+ auto res = cli_.Get (" /streamed-with-range" , Headers {{" Range" , " bytes=-3" }});
2194
2222
ASSERT_TRUE (res);
2195
2223
EXPECT_EQ (206 , res->status );
2196
2224
EXPECT_EQ (" 3" , res->get_header_value (" Content-Length" ));
@@ -2199,7 +2227,8 @@ TEST_F(ServerTest, GetStreamedWithRangeSuffix1) {
2199
2227
}
2200
2228
2201
2229
TEST_F (ServerTest, GetStreamedWithRangeSuffix2) {
2202
- auto res = cli_.Get (" /streamed-with-range" , {{" Range" , " bytes=-9999" }});
2230
+ auto res =
2231
+ cli_.Get (" /streamed-with-range" , Headers{{" Range" , " bytes=-9999" }});
2203
2232
ASSERT_TRUE (res);
2204
2233
EXPECT_EQ (206 , res->status );
2205
2234
EXPECT_EQ (" 7" , res->get_header_value (" Content-Length" ));
@@ -2208,25 +2237,26 @@ TEST_F(ServerTest, GetStreamedWithRangeSuffix2) {
2208
2237
}
2209
2238
2210
2239
TEST_F (ServerTest, GetStreamedWithRangeError) {
2211
- auto res = cli_.Get (" /streamed-with-range" ,
2212
- {{" Range" , " bytes=92233720368547758079223372036854775806-"
2240
+ auto res =
2241
+ cli_.Get (" /streamed-with-range" ,
2242
+ Headers{{" Range" , " bytes=92233720368547758079223372036854775806-"
2213
2243
" 92233720368547758079223372036854775807" }});
2214
2244
ASSERT_TRUE (res);
2215
2245
EXPECT_EQ (416 , res->status );
2216
2246
}
2217
2247
2218
2248
TEST_F (ServerTest, GetRangeWithMaxLongLength) {
2219
- auto res =
2220
- cli_. Get ( " /with-range " , {{" Range" , " bytes=0-9223372036854775807" }});
2249
+ auto res = cli_. Get ( " /with-range " ,
2250
+ Headers {{" Range" , " bytes=0-9223372036854775807" }});
2221
2251
EXPECT_EQ (206 , res->status );
2222
2252
EXPECT_EQ (" 7" , res->get_header_value (" Content-Length" ));
2223
2253
EXPECT_EQ (true , res->has_header (" Content-Range" ));
2224
2254
EXPECT_EQ (std::string (" abcdefg" ), res->body );
2225
2255
}
2226
2256
2227
2257
TEST_F (ServerTest, GetStreamedWithRangeMultipart) {
2228
- auto res =
2229
- cli_. Get ( " /streamed-with-range " , {{make_range_header ({{1 , 2 }, {4 , 5 }})}});
2258
+ auto res = cli_. Get ( " /streamed-with-range " ,
2259
+ Headers {{make_range_header ({{1 , 2 }, {4 , 5 }})}});
2230
2260
ASSERT_TRUE (res);
2231
2261
EXPECT_EQ (206 , res->status );
2232
2262
EXPECT_EQ (" 269" , res->get_header_value (" Content-Length" ));
@@ -2270,7 +2300,7 @@ TEST_F(ServerTest, ClientStop) {
2270
2300
}
2271
2301
2272
2302
TEST_F (ServerTest, GetWithRange1) {
2273
- auto res = cli_.Get (" /with-range" , {{make_range_header ({{3 , 5 }})}});
2303
+ auto res = cli_.Get (" /with-range" , Headers {{make_range_header ({{3 , 5 }})}});
2274
2304
ASSERT_TRUE (res);
2275
2305
EXPECT_EQ (206 , res->status );
2276
2306
EXPECT_EQ (" 3" , res->get_header_value (" Content-Length" ));
@@ -2279,7 +2309,7 @@ TEST_F(ServerTest, GetWithRange1) {
2279
2309
}
2280
2310
2281
2311
TEST_F (ServerTest, GetWithRange2) {
2282
- auto res = cli_.Get (" /with-range" , {{make_range_header ({{1 , -1 }})}});
2312
+ auto res = cli_.Get (" /with-range" , Headers {{make_range_header ({{1 , -1 }})}});
2283
2313
ASSERT_TRUE (res);
2284
2314
EXPECT_EQ (206 , res->status );
2285
2315
EXPECT_EQ (" 6" , res->get_header_value (" Content-Length" ));
@@ -2288,7 +2318,7 @@ TEST_F(ServerTest, GetWithRange2) {
2288
2318
}
2289
2319
2290
2320
TEST_F (ServerTest, GetWithRange3) {
2291
- auto res = cli_.Get (" /with-range" , {{make_range_header ({{0 , 0 }})}});
2321
+ auto res = cli_.Get (" /with-range" , Headers {{make_range_header ({{0 , 0 }})}});
2292
2322
ASSERT_TRUE (res);
2293
2323
EXPECT_EQ (206 , res->status );
2294
2324
EXPECT_EQ (" 1" , res->get_header_value (" Content-Length" ));
@@ -2297,7 +2327,7 @@ TEST_F(ServerTest, GetWithRange3) {
2297
2327
}
2298
2328
2299
2329
TEST_F (ServerTest, GetWithRange4) {
2300
- auto res = cli_.Get (" /with-range" , {{make_range_header ({{-1 , 2 }})}});
2330
+ auto res = cli_.Get (" /with-range" , Headers {{make_range_header ({{-1 , 2 }})}});
2301
2331
ASSERT_TRUE (res);
2302
2332
EXPECT_EQ (206 , res->status );
2303
2333
EXPECT_EQ (" 2" , res->get_header_value (" Content-Length" ));
@@ -2306,13 +2336,15 @@ TEST_F(ServerTest, GetWithRange4) {
2306
2336
}
2307
2337
2308
2338
TEST_F (ServerTest, GetWithRangeOffsetGreaterThanContent) {
2309
- auto res = cli_.Get (" /with-range" , {{make_range_header ({{10000 , 20000 }})}});
2339
+ auto res =
2340
+ cli_.Get (" /with-range" , Headers{{make_range_header ({{10000 , 20000 }})}});
2310
2341
ASSERT_TRUE (res);
2311
2342
EXPECT_EQ (416 , res->status );
2312
2343
}
2313
2344
2314
2345
TEST_F (ServerTest, GetWithRangeMultipart) {
2315
- auto res = cli_.Get (" /with-range" , {{make_range_header ({{1 , 2 }, {4 , 5 }})}});
2346
+ auto res =
2347
+ cli_.Get (" /with-range" , Headers{{make_range_header ({{1 , 2 }, {4 , 5 }})}});
2316
2348
ASSERT_TRUE (res);
2317
2349
EXPECT_EQ (206 , res->status );
2318
2350
EXPECT_EQ (" 269" , res->get_header_value (" Content-Length" ));
@@ -2321,8 +2353,8 @@ TEST_F(ServerTest, GetWithRangeMultipart) {
2321
2353
}
2322
2354
2323
2355
TEST_F (ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
2324
- auto res =
2325
- cli_. Get ( " /with-range " , {{make_range_header ({{-1 , 2 }, {10000 , 30000 }})}});
2356
+ auto res = cli_. Get ( " /with-range " ,
2357
+ Headers {{make_range_header ({{-1 , 2 }, {10000 , 30000 }})}});
2326
2358
ASSERT_TRUE (res);
2327
2359
EXPECT_EQ (416 , res->status );
2328
2360
}
@@ -3968,8 +4000,8 @@ TEST(YahooRedirectTest3, NewResultInterface) {
3968
4000
#ifdef CPPHTTPLIB_BROTLI_SUPPORT
3969
4001
TEST (DecodeWithChunkedEncoding, BrotliEncoding) {
3970
4002
Client cli (" https://cdnjs.cloudflare.com" );
3971
- auto res =
3972
- cli. Get ( " /ajax/libs/jquery/3.5.1/jquery.js " , {{" Accept-Encoding" , " br" }});
4003
+ auto res = cli. Get ( " /ajax/libs/jquery/3.5.1/jquery.js " ,
4004
+ Headers {{" Accept-Encoding" , " br" }});
3973
4005
3974
4006
ASSERT_TRUE (res);
3975
4007
EXPECT_EQ (200 , res->status );
@@ -3979,7 +4011,7 @@ TEST(DecodeWithChunkedEncoding, BrotliEncoding) {
3979
4011
}
3980
4012
#endif
3981
4013
3982
- TEST (HttpsToHttpRedirectTest2 , SimpleInterface) {
4014
+ TEST (HttpsToHttpRedirectTest , SimpleInterface) {
3983
4015
Client cli (" https://nghttp2.org" );
3984
4016
cli.set_follow_location (true );
3985
4017
auto res =
@@ -3989,4 +4021,29 @@ TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
3989
4021
ASSERT_TRUE (res);
3990
4022
EXPECT_EQ (200 , res->status );
3991
4023
}
4024
+
4025
+ TEST (HttpsToHttpRedirectTest2, SimpleInterface) {
4026
+ Client cli (" https://nghttp2.org" );
4027
+ cli.set_follow_location (true );
4028
+
4029
+ Params params;
4030
+ params.emplace (" url" , " http://www.google.com" );
4031
+ params.emplace (" status_code" , " 302" );
4032
+
4033
+ auto res = cli.Get (" /httpbin/redirect-to" , params);
4034
+ ASSERT_TRUE (res);
4035
+ EXPECT_EQ (200 , res->status );
4036
+ }
4037
+
4038
+ TEST (HttpsToHttpRedirectTest3, SimpleInterface) {
4039
+ Client cli (" https://nghttp2.org" );
4040
+ cli.set_follow_location (true );
4041
+
4042
+ Params params;
4043
+ params.emplace (" url" , " http://www.google.com" );
4044
+
4045
+ auto res = cli.Get (" /httpbin/redirect-to?status_code=302" , params);
4046
+ ASSERT_TRUE (res);
4047
+ EXPECT_EQ (200 , res->status );
4048
+ }
3992
4049
#endif
0 commit comments