Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ed1cf8f

Browse files
committedDec 23, 2024·
Cleaner API (breaking change)
1 parent 8794792 commit ed1cf8f

File tree

3 files changed

+260
-512
lines changed

3 files changed

+260
-512
lines changed
 

‎README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ auto res = cli.Get("/hi", headers);
563563
```
564564
or
565565
```c++
566-
auto res = cli.Get("/hi", {{"Hello", "World!"}});
566+
auto res = cli.Get("/hi", httplib::Headers{{"Hello", "World!"}});
567567
```
568568
or
569569
```c++
@@ -657,7 +657,7 @@ auto res = cli.Get("/large-data",
657657
std::string body;
658658
659659
auto res = cli.Get(
660-
"/stream", Headers(),
660+
"/stream",
661661
[&](const Response &response) {
662662
EXPECT_EQ(StatusCode::OK_200, response.status);
663663
return true; // return 'false' if you want to cancel the request.
@@ -829,13 +829,13 @@ The default `Acdcept-Encoding` value contains all possible compression types. So
829829

830830
```c++
831831
res = cli.Get("/resource/foo");
832-
res = cli.Get("/resource/foo", {{"Accept-Encoding", "gzip, deflate, br"}});
832+
res = cli.Get("/resource/foo", httplib::Headers{{"Accept-Encoding", "gzip, deflate, br"}});
833833
```
834834
835835
If we don't want a response without compression, we have to set `Accept-Encoding` to an empty string. This behavior is similar to curl.
836836
837837
```c++
838-
res = cli.Get("/resource/foo", {{"Accept-Encoding", ""}});
838+
res = cli.Get("/resource/foo", httplib::Headers{{"Accept-Encoding", ""}});
839839
```
840840

841841
### Compress request body on client

‎httplib.h

Lines changed: 124 additions & 393 deletions
Large diffs are not rendered by default.

‎test/test.cc

Lines changed: 132 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -513,37 +513,37 @@ TEST(GetHeaderValueTest, RegularValueInt) {
513513

514514
TEST(GetHeaderValueTest, Range) {
515515
{
516-
Headers headers = {make_range_header({{1, -1}})};
516+
auto headers = Headers{make_range_header({{1, -1}})};
517517
auto val = detail::get_header_value(headers, "Range", 0, 0);
518518
EXPECT_STREQ("bytes=1-", val);
519519
}
520520

521521
{
522-
Headers headers = {make_range_header({{-1, 1}})};
522+
auto headers = Headers{make_range_header({{-1, 1}})};
523523
auto val = detail::get_header_value(headers, "Range", 0, 0);
524524
EXPECT_STREQ("bytes=-1", val);
525525
}
526526

527527
{
528-
Headers headers = {make_range_header({{1, 10}})};
528+
auto headers = Headers{make_range_header({{1, 10}})};
529529
auto val = detail::get_header_value(headers, "Range", 0, 0);
530530
EXPECT_STREQ("bytes=1-10", val);
531531
}
532532

533533
{
534-
Headers headers = {make_range_header({{1, 10}, {100, -1}})};
534+
auto headers = Headers{make_range_header({{1, 10}, {100, -1}})};
535535
auto val = detail::get_header_value(headers, "Range", 0, 0);
536536
EXPECT_STREQ("bytes=1-10, 100-", val);
537537
}
538538

539539
{
540-
Headers headers = {make_range_header({{1, 10}, {100, 200}})};
540+
auto headers = Headers{make_range_header({{1, 10}, {100, 200}})};
541541
auto val = detail::get_header_value(headers, "Range", 0, 0);
542542
EXPECT_STREQ("bytes=1-10, 100-200", val);
543543
}
544544

545545
{
546-
Headers headers = {make_range_header({{0, 0}, {-1, 1}})};
546+
auto headers = Headers{make_range_header({{0, 0}, {-1, 1}})};
547547
auto val = detail::get_header_value(headers, "Range", 0, 0);
548548
EXPECT_STREQ("bytes=0-0, -1", val);
549549
}
@@ -789,24 +789,47 @@ TEST(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver_Online) {
789789
#endif
790790
cli.set_connection_timeout(2);
791791

792-
std::string body;
793-
auto res = cli.Get(
794-
"/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137",
795-
[&](const Response &response) {
796-
EXPECT_EQ(StatusCode::OK_200, response.status);
797-
return true;
798-
},
799-
[&](const char *data, size_t data_length) {
800-
body.append(data, data_length);
801-
return true;
802-
});
803-
ASSERT_TRUE(res);
792+
{
793+
std::string body;
794+
auto res = cli.Get(
795+
"/httpgallery/chunked/chunkedimage.aspx",
796+
[&](const Response &response) {
797+
EXPECT_EQ(StatusCode::OK_200, response.status);
798+
return true;
799+
},
800+
[&](const char *data, size_t data_length) {
801+
body.append(data, data_length);
802+
return true;
803+
});
804+
ASSERT_TRUE(res);
804805

805-
std::string out;
806-
detail::read_file("./image.jpg", out);
806+
std::string out;
807+
detail::read_file("./image.jpg", out);
807808

808-
EXPECT_EQ(StatusCode::OK_200, res->status);
809-
EXPECT_EQ(out, body);
809+
EXPECT_EQ(StatusCode::OK_200, res->status);
810+
EXPECT_EQ(out, body);
811+
}
812+
813+
{
814+
std::string body;
815+
auto res = cli.Get(
816+
"/httpgallery/chunked/chunkedimage.aspx", Params{},
817+
[&](const Response &response) {
818+
EXPECT_EQ(StatusCode::OK_200, response.status);
819+
return true;
820+
},
821+
[&](const char *data, size_t data_length) {
822+
body.append(data, data_length);
823+
return true;
824+
});
825+
ASSERT_TRUE(res);
826+
827+
std::string out;
828+
detail::read_file("./image.jpg", out);
829+
830+
EXPECT_EQ(StatusCode::OK_200, res->status);
831+
EXPECT_EQ(out, body);
832+
}
810833
}
811834

812835
TEST(RangeTest, FromHTTPBin_Online) {
@@ -835,39 +858,39 @@ TEST(RangeTest, FromHTTPBin_Online) {
835858
}
836859

837860
{
838-
Headers headers = {make_range_header({{1, -1}})};
861+
auto headers = Headers{make_range_header({{1, -1}})};
839862
auto res = cli.Get(path, headers);
840863
ASSERT_TRUE(res);
841864
EXPECT_EQ("bcdefghijklmnopqrstuvwxyzabcdef", res->body);
842865
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
843866
}
844867

845868
{
846-
Headers headers = {make_range_header({{1, 10}})};
869+
auto headers = Headers{make_range_header({{1, 10}})};
847870
auto res = cli.Get(path, headers);
848871
ASSERT_TRUE(res);
849872
EXPECT_EQ("bcdefghijk", res->body);
850873
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
851874
}
852875

853876
{
854-
Headers headers = {make_range_header({{0, 31}})};
877+
auto headers = Headers{make_range_header({{0, 31}})};
855878
auto res = cli.Get(path, headers);
856879
ASSERT_TRUE(res);
857880
EXPECT_EQ("abcdefghijklmnopqrstuvwxyzabcdef", res->body);
858881
EXPECT_EQ(StatusCode::OK_200, res->status);
859882
}
860883

861884
{
862-
Headers headers = {make_range_header({{0, -1}})};
885+
auto headers = Headers{make_range_header({{0, -1}})};
863886
auto res = cli.Get(path, headers);
864887
ASSERT_TRUE(res);
865888
EXPECT_EQ("abcdefghijklmnopqrstuvwxyzabcdef", res->body);
866889
EXPECT_EQ(StatusCode::OK_200, res->status);
867890
}
868891

869892
{
870-
Headers headers = {make_range_header({{0, 32}})};
893+
auto headers = Headers{make_range_header({{0, 32}})};
871894
auto res = cli.Get(path, headers);
872895
ASSERT_TRUE(res);
873896
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
@@ -1053,9 +1076,8 @@ TEST(CancelTest, NoCancelPost) {
10531076
Client cli(HOST, PORT);
10541077
cli.set_connection_timeout(std::chrono::seconds(5));
10551078

1056-
auto res =
1057-
cli.Post("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1058-
"application/json", [](uint64_t, uint64_t) { return true; });
1079+
auto res = cli.Post("/", JSON_DATA, "application/json",
1080+
[](uint64_t, uint64_t) { return true; });
10591081
ASSERT_TRUE(res);
10601082
EXPECT_EQ("Hello World!", res->body);
10611083
EXPECT_EQ(StatusCode::OK_200, res->status);
@@ -1080,9 +1102,8 @@ TEST(CancelTest, WithCancelSmallPayloadPost) {
10801102
Client cli(HOST, PORT);
10811103
cli.set_connection_timeout(std::chrono::seconds(5));
10821104

1083-
auto res =
1084-
cli.Post("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1085-
"application/json", [](uint64_t, uint64_t) { return false; });
1105+
auto res = cli.Post("/", JSON_DATA, "application/json",
1106+
[](uint64_t, uint64_t) { return false; });
10861107
ASSERT_TRUE(!res);
10871108
EXPECT_EQ(Error::Canceled, res.error());
10881109
}
@@ -1106,9 +1127,8 @@ TEST(CancelTest, WithCancelLargePayloadPost) {
11061127
Client cli(HOST, PORT);
11071128
cli.set_connection_timeout(std::chrono::seconds(5));
11081129

1109-
auto res =
1110-
cli.Post("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1111-
"application/json", [](uint64_t, uint64_t) { return false; });
1130+
auto res = cli.Post("/", JSON_DATA, "application/json",
1131+
[](uint64_t, uint64_t) { return false; });
11121132
ASSERT_TRUE(!res);
11131133
EXPECT_EQ(Error::Canceled, res.error());
11141134
}
@@ -1132,9 +1152,8 @@ TEST(CancelTest, NoCancelPut) {
11321152
Client cli(HOST, PORT);
11331153
cli.set_connection_timeout(std::chrono::seconds(5));
11341154

1135-
auto res =
1136-
cli.Put("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1137-
"application/json", [](uint64_t, uint64_t) { return true; });
1155+
auto res = cli.Put("/", JSON_DATA, "application/json",
1156+
[](uint64_t, uint64_t) { return true; });
11381157
ASSERT_TRUE(res);
11391158
EXPECT_EQ("Hello World!", res->body);
11401159
EXPECT_EQ(StatusCode::OK_200, res->status);
@@ -1159,9 +1178,8 @@ TEST(CancelTest, WithCancelSmallPayloadPut) {
11591178
Client cli(HOST, PORT);
11601179
cli.set_connection_timeout(std::chrono::seconds(5));
11611180

1162-
auto res =
1163-
cli.Put("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1164-
"application/json", [](uint64_t, uint64_t) { return false; });
1181+
auto res = cli.Put("/", JSON_DATA, "application/json",
1182+
[](uint64_t, uint64_t) { return false; });
11651183
ASSERT_TRUE(!res);
11661184
EXPECT_EQ(Error::Canceled, res.error());
11671185
}
@@ -1185,9 +1203,8 @@ TEST(CancelTest, WithCancelLargePayloadPut) {
11851203
Client cli(HOST, PORT);
11861204
cli.set_connection_timeout(std::chrono::seconds(5));
11871205

1188-
auto res =
1189-
cli.Put("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1190-
"application/json", [](uint64_t, uint64_t) { return false; });
1206+
auto res = cli.Put("/", JSON_DATA, "application/json",
1207+
[](uint64_t, uint64_t) { return false; });
11911208
ASSERT_TRUE(!res);
11921209
EXPECT_EQ(Error::Canceled, res.error());
11931210
}
@@ -1211,9 +1228,8 @@ TEST(CancelTest, NoCancelPatch) {
12111228
Client cli(HOST, PORT);
12121229
cli.set_connection_timeout(std::chrono::seconds(5));
12131230

1214-
auto res =
1215-
cli.Patch("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1216-
"application/json", [](uint64_t, uint64_t) { return true; });
1231+
auto res = cli.Patch("/", JSON_DATA, "application/json",
1232+
[](uint64_t, uint64_t) { return true; });
12171233
ASSERT_TRUE(res);
12181234
EXPECT_EQ("Hello World!", res->body);
12191235
EXPECT_EQ(StatusCode::OK_200, res->status);
@@ -1238,9 +1254,8 @@ TEST(CancelTest, WithCancelSmallPayloadPatch) {
12381254
Client cli(HOST, PORT);
12391255
cli.set_connection_timeout(std::chrono::seconds(5));
12401256

1241-
auto res =
1242-
cli.Patch("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1243-
"application/json", [](uint64_t, uint64_t) { return false; });
1257+
auto res = cli.Patch("/", JSON_DATA, "application/json",
1258+
[](uint64_t, uint64_t) { return false; });
12441259
ASSERT_TRUE(!res);
12451260
EXPECT_EQ(Error::Canceled, res.error());
12461261
}
@@ -1264,9 +1279,8 @@ TEST(CancelTest, WithCancelLargePayloadPatch) {
12641279
Client cli(HOST, PORT);
12651280
cli.set_connection_timeout(std::chrono::seconds(5));
12661281

1267-
auto res =
1268-
cli.Patch("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1269-
"application/json", [](uint64_t, uint64_t) { return false; });
1282+
auto res = cli.Patch("/", JSON_DATA, "application/json",
1283+
[](uint64_t, uint64_t) { return false; });
12701284
ASSERT_TRUE(!res);
12711285
EXPECT_EQ(Error::Canceled, res.error());
12721286
}
@@ -1290,9 +1304,8 @@ TEST(CancelTest, NoCancelDelete) {
12901304
Client cli(HOST, PORT);
12911305
cli.set_connection_timeout(std::chrono::seconds(5));
12921306

1293-
auto res =
1294-
cli.Delete("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1295-
"application/json", [](uint64_t, uint64_t) { return true; });
1307+
auto res = cli.Delete("/", JSON_DATA, "application/json",
1308+
[](uint64_t, uint64_t) { return true; });
12961309
ASSERT_TRUE(res);
12971310
EXPECT_EQ("Hello World!", res->body);
12981311
EXPECT_EQ(StatusCode::OK_200, res->status);
@@ -1317,9 +1330,8 @@ TEST(CancelTest, WithCancelSmallPayloadDelete) {
13171330
Client cli(HOST, PORT);
13181331
cli.set_connection_timeout(std::chrono::seconds(5));
13191332

1320-
auto res =
1321-
cli.Delete("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1322-
"application/json", [](uint64_t, uint64_t) { return false; });
1333+
auto res = cli.Delete("/", JSON_DATA, "application/json",
1334+
[](uint64_t, uint64_t) { return false; });
13231335
ASSERT_TRUE(!res);
13241336
EXPECT_EQ(Error::Canceled, res.error());
13251337
}
@@ -1343,9 +1355,8 @@ TEST(CancelTest, WithCancelLargePayloadDelete) {
13431355
Client cli(HOST, PORT);
13441356
cli.set_connection_timeout(std::chrono::seconds(5));
13451357

1346-
auto res =
1347-
cli.Delete("/", Headers(), JSON_DATA.data(), JSON_DATA.size(),
1348-
"application/json", [](uint64_t, uint64_t) { return false; });
1358+
auto res = cli.Delete("/", JSON_DATA, "application/json",
1359+
[](uint64_t, uint64_t) { return false; });
13491360
ASSERT_TRUE(!res);
13501361
EXPECT_EQ(Error::Canceled, res.error());
13511362
}
@@ -1374,8 +1385,8 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
13741385
}
13751386

13761387
{
1377-
auto res =
1378-
cli.Get(path, {make_basic_authentication_header("hello", "world")});
1388+
auto res = cli.Get(
1389+
path, Headers{make_basic_authentication_header("hello", "world")});
13791390
ASSERT_TRUE(res);
13801391
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n",
13811392
res->body);
@@ -1592,7 +1603,7 @@ TEST(HttpsToHttpRedirectTest2, Redirect_Online) {
15921603
params.emplace("url", "http://www.google.com");
15931604
params.emplace("status_code", "302");
15941605

1595-
auto res = cli.Get("/httpbin/redirect-to", params, Headers{});
1606+
auto res = cli.Get("/httpbin/redirect-to", params);
15961607
ASSERT_TRUE(res);
15971608
EXPECT_EQ(StatusCode::OK_200, res->status);
15981609
}
@@ -1604,7 +1615,7 @@ TEST(HttpsToHttpRedirectTest3, Redirect_Online) {
16041615
Params params;
16051616
params.emplace("url", "http://www.google.com");
16061617

1607-
auto res = cli.Get("/httpbin/redirect-to?status_code=302", params, Headers{});
1618+
auto res = cli.Get("/httpbin/redirect-to?status_code=302", params);
16081619
ASSERT_TRUE(res);
16091620
EXPECT_EQ(StatusCode::OK_200, res->status);
16101621
}
@@ -2004,7 +2015,7 @@ TEST(ErrorHandlerTest, ContentLength) {
20042015
{
20052016
Client cli(HOST, PORT);
20062017

2007-
auto res = cli.Get("/hi", {{"Accept-Encoding", ""}});
2018+
auto res = cli.Get("/hi", Headers{{"Accept-Encoding", ""}});
20082019
ASSERT_TRUE(res);
20092020
EXPECT_EQ(StatusCode::OK_200, res->status);
20102021
EXPECT_EQ("text/html", res->get_header_value("Content-Type"));
@@ -2087,7 +2098,7 @@ TEST(ExceptionTest, WithExceptionHandler) {
20872098
Client cli(HOST, PORT);
20882099

20892100
for (size_t j = 0; j < 100; j++) {
2090-
auto res = cli.Get("/hi", {{"Accept-Encoding", ""}});
2101+
auto res = cli.Get("/hi", Headers{{"Accept-Encoding", ""}});
20912102
ASSERT_TRUE(res);
20922103
EXPECT_EQ(StatusCode::InternalServerError_500, res->status);
20932104
EXPECT_EQ("text/html", res->get_header_value("Content-Type"));
@@ -2098,7 +2109,7 @@ TEST(ExceptionTest, WithExceptionHandler) {
20982109
cli.set_keep_alive(true);
20992110

21002111
for (size_t j = 0; j < 100; j++) {
2101-
auto res = cli.Get("/hi", {{"Accept-Encoding", ""}});
2112+
auto res = cli.Get("/hi", Headers{{"Accept-Encoding", ""}});
21022113
ASSERT_TRUE(res);
21032114
EXPECT_EQ(StatusCode::InternalServerError_500, res->status);
21042115
EXPECT_EQ("text/html", res->get_header_value("Content-Type"));
@@ -3349,7 +3360,7 @@ TEST_F(ServerTest, UserDefinedMIMETypeMapping) {
33493360
}
33503361

33513362
TEST_F(ServerTest, StaticFileRange) {
3352-
auto res = cli_.Get("/dir/test.abcde", {{make_range_header({{2, 3}})}});
3363+
auto res = cli_.Get("/dir/test.abcde", Headers{make_range_header({{2, 3}})});
33533364
ASSERT_TRUE(res);
33543365
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
33553366
EXPECT_EQ("text/abcde", res->get_header_value("Content-Type"));
@@ -3360,8 +3371,8 @@ TEST_F(ServerTest, StaticFileRange) {
33603371
}
33613372

33623373
TEST_F(ServerTest, StaticFileRanges) {
3363-
auto res =
3364-
cli_.Get("/dir/test.abcde", {{make_range_header({{1, 2}, {4, -1}})}});
3374+
auto res = cli_.Get("/dir/test.abcde",
3375+
Headers{make_range_header({{1, 2}, {4, -1}})});
33653376
ASSERT_TRUE(res);
33663377
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
33673378
EXPECT_TRUE(
@@ -3373,7 +3384,7 @@ TEST_F(ServerTest, StaticFileRanges) {
33733384
}
33743385

33753386
TEST_F(ServerTest, StaticFileRangeHead) {
3376-
auto res = cli_.Head("/dir/test.abcde", {{make_range_header({{2, 3}})}});
3387+
auto res = cli_.Head("/dir/test.abcde", Headers{make_range_header({{2, 3}})});
33773388
ASSERT_TRUE(res);
33783389
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
33793390
EXPECT_EQ("text/abcde", res->get_header_value("Content-Type"));
@@ -3383,7 +3394,7 @@ TEST_F(ServerTest, StaticFileRangeHead) {
33833394
}
33843395

33853396
TEST_F(ServerTest, StaticFileRangeBigFile) {
3386-
auto res = cli_.Get("/dir/1MB.txt", {{make_range_header({{-1, 5}})}});
3397+
auto res = cli_.Get("/dir/1MB.txt", Headers{make_range_header({{-1, 5}})});
33873398
ASSERT_TRUE(res);
33883399
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
33893400
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
@@ -3395,7 +3406,7 @@ TEST_F(ServerTest, StaticFileRangeBigFile) {
33953406
}
33963407

33973408
TEST_F(ServerTest, StaticFileRangeBigFile2) {
3398-
auto res = cli_.Get("/dir/1MB.txt", {{make_range_header({{1, 4097}})}});
3409+
auto res = cli_.Get("/dir/1MB.txt", Headers{make_range_header({{1, 4097}})});
33993410
ASSERT_TRUE(res);
34003411
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
34013412
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
@@ -3724,7 +3735,7 @@ TEST_F(ServerTest, CaseInsensitiveTransferEncoding) {
37243735
}
37253736

37263737
TEST_F(ServerTest, GetStreamed2) {
3727-
auto res = cli_.Get("/streamed", {{make_range_header({{2, 3}})}});
3738+
auto res = cli_.Get("/streamed", Headers{make_range_header({{2, 3}})});
37283739
ASSERT_TRUE(res);
37293740
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
37303741
EXPECT_EQ("2", res->get_header_value("Content-Length"));
@@ -3742,7 +3753,8 @@ TEST_F(ServerTest, GetStreamed) {
37423753
}
37433754

37443755
TEST_F(ServerTest, GetStreamedWithRange1) {
3745-
auto res = cli_.Get("/streamed-with-range", {{make_range_header({{3, 5}})}});
3756+
auto res =
3757+
cli_.Get("/streamed-with-range", Headers{make_range_header({{3, 5}})});
37463758
ASSERT_TRUE(res);
37473759
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
37483760
EXPECT_EQ("3", res->get_header_value("Content-Length"));
@@ -3752,7 +3764,8 @@ TEST_F(ServerTest, GetStreamedWithRange1) {
37523764
}
37533765

37543766
TEST_F(ServerTest, GetStreamedWithRange2) {
3755-
auto res = cli_.Get("/streamed-with-range", {{make_range_header({{1, -1}})}});
3767+
auto res =
3768+
cli_.Get("/streamed-with-range", Headers{make_range_header({{1, -1}})});
37563769
ASSERT_TRUE(res);
37573770
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
37583771
EXPECT_EQ("6", res->get_header_value("Content-Length"));
@@ -3762,7 +3775,7 @@ TEST_F(ServerTest, GetStreamedWithRange2) {
37623775
}
37633776

37643777
TEST_F(ServerTest, GetStreamedWithRangeSuffix1) {
3765-
auto res = cli_.Get("/streamed-with-range", {{"Range", "bytes=-3"}});
3778+
auto res = cli_.Get("/streamed-with-range", Headers{{"Range", "bytes=-3"}});
37663779
ASSERT_TRUE(res);
37673780
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
37683781
EXPECT_EQ("3", res->get_header_value("Content-Length"));
@@ -3772,7 +3785,8 @@ TEST_F(ServerTest, GetStreamedWithRangeSuffix1) {
37723785
}
37733786

37743787
TEST_F(ServerTest, GetStreamedWithRangeSuffix2) {
3775-
auto res = cli_.Get("/streamed-with-range?error", {{"Range", "bytes=-9999"}});
3788+
auto res =
3789+
cli_.Get("/streamed-with-range?error", Headers{{"Range", "bytes=-9999"}});
37763790
ASSERT_TRUE(res);
37773791
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
37783792
EXPECT_EQ("0", res->get_header_value("Content-Length"));
@@ -3781,8 +3795,9 @@ TEST_F(ServerTest, GetStreamedWithRangeSuffix2) {
37813795
}
37823796

37833797
TEST_F(ServerTest, GetStreamedWithRangeError) {
3784-
auto res = cli_.Get("/streamed-with-range",
3785-
{{"Range", "bytes=92233720368547758079223372036854775806-"
3798+
auto res =
3799+
cli_.Get("/streamed-with-range",
3800+
Headers{{"Range", "bytes=92233720368547758079223372036854775806-"
37863801
"92233720368547758079223372036854775807"}});
37873802
ASSERT_TRUE(res);
37883803
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
@@ -3806,7 +3821,7 @@ TEST_F(ServerTest, GetRangeWithMaxLongLength) {
38063821
}
38073822

38083823
TEST_F(ServerTest, GetRangeWithZeroToInfinite) {
3809-
auto res = cli_.Get("/with-range", {
3824+
auto res = cli_.Get("/with-range", Headers{
38103825
{"Range", "bytes=0-"},
38113826
{"Accept-Encoding", ""},
38123827
});
@@ -3819,8 +3834,8 @@ TEST_F(ServerTest, GetRangeWithZeroToInfinite) {
38193834
}
38203835

38213836
TEST_F(ServerTest, GetStreamedWithRangeMultipart) {
3822-
auto res =
3823-
cli_.Get("/streamed-with-range", {{make_range_header({{1, 2}, {4, 5}})}});
3837+
auto res = cli_.Get("/streamed-with-range",
3838+
Headers{make_range_header({{1, 2}, {4, 5}})});
38243839
ASSERT_TRUE(res);
38253840
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
38263841
EXPECT_EQ("267", res->get_header_value("Content-Length"));
@@ -3834,8 +3849,8 @@ TEST_F(ServerTest, GetStreamedWithTooManyRanges) {
38343849
ranges.emplace_back(0, -1);
38353850
}
38363851

3837-
auto res =
3838-
cli_.Get("/streamed-with-range?error", {{make_range_header(ranges)}});
3852+
auto res = cli_.Get("/streamed-with-range?error",
3853+
Headers{make_range_header(ranges)});
38393854
ASSERT_TRUE(res);
38403855
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
38413856
EXPECT_EQ("0", res->get_header_value("Content-Length"));
@@ -3845,7 +3860,7 @@ TEST_F(ServerTest, GetStreamedWithTooManyRanges) {
38453860

38463861
TEST_F(ServerTest, GetStreamedWithNonAscendingRanges) {
38473862
auto res = cli_.Get("/streamed-with-range?error",
3848-
{{make_range_header({{0, -1}, {0, -1}})}});
3863+
Headers{make_range_header({{0, -1}, {0, -1}})});
38493864
ASSERT_TRUE(res);
38503865
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
38513866
EXPECT_EQ("0", res->get_header_value("Content-Length"));
@@ -3854,8 +3869,9 @@ TEST_F(ServerTest, GetStreamedWithNonAscendingRanges) {
38543869
}
38553870

38563871
TEST_F(ServerTest, GetStreamedWithRangesMoreThanTwoOverwrapping) {
3857-
auto res = cli_.Get("/streamed-with-range?error",
3858-
{{make_range_header({{0, 1}, {1, 2}, {2, 3}, {3, 4}})}});
3872+
auto res =
3873+
cli_.Get("/streamed-with-range?error",
3874+
Headers{make_range_header({{0, 1}, {1, 2}, {2, 3}, {3, 4}})});
38593875
ASSERT_TRUE(res);
38603876
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
38613877
EXPECT_EQ("0", res->get_header_value("Content-Length"));
@@ -3905,7 +3921,7 @@ TEST_F(ServerTest, ClientStop) {
39053921
}
39063922

39073923
TEST_F(ServerTest, GetWithRange1) {
3908-
auto res = cli_.Get("/with-range", {
3924+
auto res = cli_.Get("/with-range", Headers{
39093925
make_range_header({{3, 5}}),
39103926
{"Accept-Encoding", ""},
39113927
});
@@ -3918,7 +3934,7 @@ TEST_F(ServerTest, GetWithRange1) {
39183934
}
39193935

39203936
TEST_F(ServerTest, GetWithRange2) {
3921-
auto res = cli_.Get("/with-range", {
3937+
auto res = cli_.Get("/with-range", Headers{
39223938
make_range_header({{1, -1}}),
39233939
{"Accept-Encoding", ""},
39243940
});
@@ -3931,7 +3947,7 @@ TEST_F(ServerTest, GetWithRange2) {
39313947
}
39323948

39333949
TEST_F(ServerTest, GetWithRange3) {
3934-
auto res = cli_.Get("/with-range", {
3950+
auto res = cli_.Get("/with-range", Headers{
39353951
make_range_header({{0, 0}}),
39363952
{"Accept-Encoding", ""},
39373953
});
@@ -3944,7 +3960,7 @@ TEST_F(ServerTest, GetWithRange3) {
39443960
}
39453961

39463962
TEST_F(ServerTest, GetWithRange4) {
3947-
auto res = cli_.Get("/with-range", {
3963+
auto res = cli_.Get("/with-range", Headers{
39483964
make_range_header({{-1, 2}}),
39493965
{"Accept-Encoding", ""},
39503966
});
@@ -3957,13 +3973,15 @@ TEST_F(ServerTest, GetWithRange4) {
39573973
}
39583974

39593975
TEST_F(ServerTest, GetWithRangeOffsetGreaterThanContent) {
3960-
auto res = cli_.Get("/with-range", {{make_range_header({{10000, 20000}})}});
3976+
auto res =
3977+
cli_.Get("/with-range", Headers{make_range_header({{10000, 20000}})});
39613978
ASSERT_TRUE(res);
39623979
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
39633980
}
39643981

39653982
TEST_F(ServerTest, GetWithRangeMultipart) {
3966-
auto res = cli_.Get("/with-range", {{make_range_header({{1, 2}, {4, 5}})}});
3983+
auto res =
3984+
cli_.Get("/with-range", Headers{make_range_header({{1, 2}, {4, 5}})});
39673985
ASSERT_TRUE(res);
39683986
EXPECT_EQ(StatusCode::PartialContent_206, res->status);
39693987
EXPECT_EQ("267", res->get_header_value("Content-Length"));
@@ -3972,15 +3990,15 @@ TEST_F(ServerTest, GetWithRangeMultipart) {
39723990
}
39733991

39743992
TEST_F(ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
3975-
auto res =
3976-
cli_.Get("/with-range", {{make_range_header({{-1, 2}, {10000, 30000}})}});
3993+
auto res = cli_.Get("/with-range",
3994+
Headers{make_range_header({{-1, 2}, {10000, 30000}})});
39773995
ASSERT_TRUE(res);
39783996
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
39793997
}
39803998

39813999
TEST_F(ServerTest, GetWithRangeCustomizedResponse) {
39824000
auto res = cli_.Get("/with-range-customized-response",
3983-
{{make_range_header({{1, 2}})}});
4001+
Headers{make_range_header({{1, 2}})});
39844002
ASSERT_TRUE(res);
39854003
EXPECT_EQ(StatusCode::BadRequest_400, res->status);
39864004
EXPECT_EQ(true, res->has_header("Content-Length"));
@@ -3990,7 +4008,7 @@ TEST_F(ServerTest, GetWithRangeCustomizedResponse) {
39904008

39914009
TEST_F(ServerTest, GetWithRangeMultipartCustomizedResponseMultipleRange) {
39924010
auto res = cli_.Get("/with-range-customized-response",
3993-
{{make_range_header({{1, 2}, {4, 5}})}});
4011+
Headers{make_range_header({{1, 2}, {4, 5}})});
39944012
ASSERT_TRUE(res);
39954013
EXPECT_EQ(StatusCode::BadRequest_400, res->status);
39964014
EXPECT_EQ(true, res->has_header("Content-Length"));
@@ -3999,7 +4017,7 @@ TEST_F(ServerTest, GetWithRangeMultipartCustomizedResponseMultipleRange) {
39994017
}
40004018

40014019
TEST_F(ServerTest, Issue1772) {
4002-
auto res = cli_.Get("/issue1772", {{make_range_header({{1000, -1}})}});
4020+
auto res = cli_.Get("/issue1772", Headers{make_range_header({{1000, -1}})});
40034021
ASSERT_TRUE(res);
40044022
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
40054023
}
@@ -5684,7 +5702,7 @@ TEST(GetWithParametersTest, GetWithParameters) {
56845702
params.emplace("hello", "world");
56855703
params.emplace("hello2", "world2");
56865704
params.emplace("hello3", "world3");
5687-
auto res = cli.Get("/", params, Headers{});
5705+
auto res = cli.Get("/", params);
56885706

56895707
ASSERT_TRUE(res);
56905708
EXPECT_EQ(StatusCode::OK_200, res->status);
@@ -5741,11 +5759,10 @@ TEST(GetWithParametersTest, GetWithParameters2) {
57415759
params.emplace("hello", "world");
57425760

57435761
std::string body;
5744-
auto res = cli.Get("/", params, Headers{},
5745-
[&](const char *data, size_t data_length) {
5746-
body.append(data, data_length);
5747-
return true;
5748-
});
5762+
auto res = cli.Get("/", params, [&](const char *data, size_t data_length) {
5763+
body.append(data, data_length);
5764+
return true;
5765+
});
57495766

57505767
ASSERT_TRUE(res);
57515768
EXPECT_EQ(StatusCode::OK_200, res->status);
@@ -5767,7 +5784,7 @@ TEST(ClientDefaultHeadersTest, DefaultHeaders_Online) {
57675784
Client cli(host);
57685785
#endif
57695786

5770-
cli.set_default_headers({make_range_header({{1, 10}})});
5787+
cli.set_default_headers(Headers{make_range_header({{1, 10}})});
57715788
cli.set_connection_timeout(5);
57725789

57735790
{
@@ -6587,7 +6604,7 @@ TEST(SendAPI, WithParamsInRequest) {
65876604
ASSERT_TRUE(res);
65886605
}
65896606
{
6590-
auto res = cli.Get("/", {{"test", "test_value"}}, Headers{});
6607+
auto res = cli.Get("/", Params{{"test", "test_value"}});
65916608
ASSERT_TRUE(res);
65926609
}
65936610
}
@@ -6716,8 +6733,8 @@ TEST(YahooRedirectTest3, NewResultInterface_Online) {
67166733
#ifdef CPPHTTPLIB_BROTLI_SUPPORT
67176734
TEST(DecodeWithChunkedEncoding, BrotliEncoding_Online) {
67186735
Client cli("https://cdnjs.cloudflare.com");
6719-
auto res =
6720-
cli.Get("/ajax/libs/jquery/3.5.1/jquery.js", {{"Accept-Encoding", "br"}});
6736+
auto res = cli.Get("/ajax/libs/jquery/3.5.1/jquery.js",
6737+
Headers{{"Accept-Encoding", "br"}});
67216738

67226739
ASSERT_TRUE(res);
67236740
EXPECT_EQ(StatusCode::OK_200, res->status);
@@ -6746,7 +6763,7 @@ TEST(HttpsToHttpRedirectTest2, SimpleInterface_Online) {
67466763
params.emplace("url", "http://www.google.com");
67476764
params.emplace("status_code", "302");
67486765

6749-
auto res = cli.Get("/httpbin/redirect-to", params, Headers{});
6766+
auto res = cli.Get("/httpbin/redirect-to", params);
67506767
ASSERT_TRUE(res);
67516768
EXPECT_EQ(StatusCode::OK_200, res->status);
67526769
}
@@ -6758,7 +6775,7 @@ TEST(HttpsToHttpRedirectTest3, SimpleInterface_Online) {
67586775
Params params;
67596776
params.emplace("url", "http://www.google.com");
67606777

6761-
auto res = cli.Get("/httpbin/redirect-to?status_code=302", params, Headers{});
6778+
auto res = cli.Get("/httpbin/redirect-to?status_code=302", params);
67626779
ASSERT_TRUE(res);
67636780
EXPECT_EQ(StatusCode::OK_200, res->status);
67646781
}
@@ -7913,7 +7930,7 @@ TEST(DirtyDataRequestTest, HeadFieldValueContains_CR_LF_NUL) {
79137930
svr.wait_until_ready();
79147931

79157932
Client cli(HOST, PORT);
7916-
cli.Get("/test", {{"Test", "_\n\r_\n\r_"}});
7933+
cli.Get("/test", Headers{{"Test", "_\n\r_\n\r_"}});
79177934
}
79187935

79197936
#ifndef _WIN32

0 commit comments

Comments
 (0)
Please sign in to comment.