mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Fixed #33
This commit is contained in:
parent
c76d0e4ab3
commit
7e5db48bdf
3 changed files with 189 additions and 51 deletions
107
test/test.cc
107
test/test.cc
|
@ -83,32 +83,59 @@ TEST(SocketTest, OpenCloseWithAI_PASSIVE)
|
|||
|
||||
TEST(GetHeaderValueTest, DefaultValue)
|
||||
{
|
||||
Headers map = {{"Dummy","Dummy"}};
|
||||
auto val = detail::get_header_value(map, "Content-Type", "text/plain");
|
||||
ASSERT_STREQ("text/plain", val);
|
||||
Headers headers = {{"Dummy","Dummy"}};
|
||||
auto val = detail::get_header_value(headers, "Content-Type", "text/plain");
|
||||
EXPECT_STREQ("text/plain", val);
|
||||
}
|
||||
|
||||
TEST(GetHeaderValueTest, DefaultValueInt)
|
||||
{
|
||||
Headers map = {{"Dummy","Dummy"}};
|
||||
auto val = detail::get_header_value_int(map, "Content-Length", 100);
|
||||
Headers headers = {{"Dummy","Dummy"}};
|
||||
auto val = detail::get_header_value_int(headers, "Content-Length", 100);
|
||||
EXPECT_EQ(100, val);
|
||||
}
|
||||
|
||||
TEST(GetHeaderValueTest, RegularValue)
|
||||
{
|
||||
Headers map = {{"Content-Type", "text/html"}, {"Dummy", "Dummy"}};
|
||||
auto val = detail::get_header_value(map, "Content-Type", "text/plain");
|
||||
ASSERT_STREQ("text/html", val);
|
||||
Headers headers = {{"Content-Type", "text/html"}, {"Dummy", "Dummy"}};
|
||||
auto val = detail::get_header_value(headers, "Content-Type", "text/plain");
|
||||
EXPECT_STREQ("text/html", val);
|
||||
}
|
||||
|
||||
TEST(GetHeaderValueTest, RegularValueInt)
|
||||
{
|
||||
Headers map = {{"Content-Length", "100"}, {"Dummy", "Dummy"}};
|
||||
auto val = detail::get_header_value_int(map, "Content-Length", 0);
|
||||
Headers headers = {{"Content-Length", "100"}, {"Dummy", "Dummy"}};
|
||||
auto val = detail::get_header_value_int(headers, "Content-Length", 0);
|
||||
EXPECT_EQ(100, val);
|
||||
}
|
||||
|
||||
TEST(GetHeaderValueTest, Range)
|
||||
{
|
||||
{
|
||||
Headers headers = { make_range_header(1) };
|
||||
auto val = detail::get_header_value(headers, "Range", 0);
|
||||
EXPECT_STREQ("bytes=1-", val);
|
||||
}
|
||||
|
||||
{
|
||||
Headers headers = { make_range_header(1, 10) };
|
||||
auto val = detail::get_header_value(headers, "Range", 0);
|
||||
EXPECT_STREQ("bytes=1-10", val);
|
||||
}
|
||||
|
||||
{
|
||||
Headers headers = { make_range_header(1, 10, 100) };
|
||||
auto val = detail::get_header_value(headers, "Range", 0);
|
||||
EXPECT_STREQ("bytes=1-10, 100-", val);
|
||||
}
|
||||
|
||||
{
|
||||
Headers headers = { make_range_header(1, 10, 100, 200) };
|
||||
auto val = detail::get_header_value(headers, "Range", 0);
|
||||
EXPECT_STREQ("bytes=1-10, 100-200", val);
|
||||
}
|
||||
}
|
||||
|
||||
void testChunkedEncoding(httplib::HttpVersion ver)
|
||||
{
|
||||
auto host = "www.httpwatch.com";
|
||||
|
@ -136,6 +163,42 @@ TEST(ChunkedEncodingTest, FromHTTPWatch)
|
|||
testChunkedEncoding(httplib::HttpVersion::v1_1);
|
||||
}
|
||||
|
||||
TEST(RangeTest, FromHTTPBin)
|
||||
{
|
||||
auto host = "httpbin.org";
|
||||
auto port = 80;
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
httplib::SSLClient cli(host, port, httplib::HttpVersion::v1_1);
|
||||
#else
|
||||
httplib::Client cli(host, port, httplib::HttpVersion::v1_1);
|
||||
#endif
|
||||
|
||||
{
|
||||
httplib::Headers headers;
|
||||
auto res = cli.get("/range/32", headers);
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
EXPECT_EQ(res->body, "abcdefghijklmnopqrstuvwxyzabcdef");
|
||||
EXPECT_EQ(200, res->status);
|
||||
}
|
||||
|
||||
{
|
||||
httplib::Headers headers = { httplib::make_range_header(1) };
|
||||
auto res = cli.get("/range/32", headers);
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
EXPECT_EQ(res->body, "bcdefghijklmnopqrstuvwxyzabcdef");
|
||||
EXPECT_EQ(206, res->status);
|
||||
}
|
||||
|
||||
{
|
||||
httplib::Headers headers = { httplib::make_range_header(1, 10) };
|
||||
auto res = cli.get("/range/32", headers);
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
EXPECT_EQ(res->body, "bcdefghijk");
|
||||
EXPECT_EQ(206, res->status);
|
||||
}
|
||||
}
|
||||
|
||||
class ServerTest : public ::testing::Test {
|
||||
protected:
|
||||
ServerTest()
|
||||
|
@ -422,11 +485,11 @@ TEST_F(ServerTest, LongHeader)
|
|||
host_and_port += ":";
|
||||
host_and_port += std::to_string(PORT);
|
||||
|
||||
req.set_header("Host", host_and_port.c_str());
|
||||
req.set_header("Accept", "*/*");
|
||||
req.set_header("User-Agent", "cpp-httplib/0.1");
|
||||
req.headers.emplace("Host", host_and_port.c_str());
|
||||
req.headers.emplace("Accept", "*/*");
|
||||
req.headers.emplace("User-Agent", "cpp-httplib/0.1");
|
||||
|
||||
req.set_header("Header-Name", "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
auto res = std::make_shared<Response>();
|
||||
auto ret = cli_.send(req, *res);
|
||||
|
@ -446,11 +509,11 @@ TEST_F(ServerTest, TooLongHeader)
|
|||
host_and_port += ":";
|
||||
host_and_port += std::to_string(PORT);
|
||||
|
||||
req.set_header("Host", host_and_port.c_str());
|
||||
req.set_header("Accept", "*/*");
|
||||
req.set_header("User-Agent", "cpp-httplib/0.1");
|
||||
req.headers.emplace("Host", host_and_port.c_str());
|
||||
req.headers.emplace("Accept", "*/*");
|
||||
req.headers.emplace("User-Agent", "cpp-httplib/0.1");
|
||||
|
||||
req.set_header("Header-Name", "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
auto res = std::make_shared<Response>();
|
||||
auto ret = cli_.send(req, *res);
|
||||
|
@ -498,10 +561,10 @@ TEST_F(ServerTest, MultipartFormData)
|
|||
host_and_port += ":";
|
||||
host_and_port += std::to_string(PORT);
|
||||
|
||||
req.set_header("Host", host_and_port.c_str());
|
||||
req.set_header("Accept", "*/*");
|
||||
req.set_header("User-Agent", "cpp-httplib/0.1");
|
||||
req.set_header("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarysBREP3G013oUrLB4");
|
||||
req.headers.emplace("Host", host_and_port.c_str());
|
||||
req.headers.emplace("Accept", "*/*");
|
||||
req.headers.emplace("User-Agent", "cpp-httplib/0.1");
|
||||
req.headers.emplace("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarysBREP3G013oUrLB4");
|
||||
|
||||
req.body = "------WebKitFormBoundarysBREP3G013oUrLB4\r\nContent-Disposition: form-data; name=\"text1\"\r\n\r\ntext default\r\n------WebKitFormBoundarysBREP3G013oUrLB4\r\nContent-Disposition: form-data; name=\"text2\"\r\n\r\naωb\r\n------WebKitFormBoundarysBREP3G013oUrLB4\r\nContent-Disposition: form-data; name=\"file1\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nh\ne\n\nl\nl\no\n\r\n------WebKitFormBoundarysBREP3G013oUrLB4\r\nContent-Disposition: form-data; name=\"file2\"; filename=\"world.json\"\r\nContent-Type: application/json\r\n\r\n{\n \"world\", true\n}\n\r\n------WebKitFormBoundarysBREP3G013oUrLB4\r\nContent-Disposition: form-data; name=\"file3\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n------WebKitFormBoundarysBREP3G013oUrLB4--\r\n";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue