|
|
|
@@ -211,8 +211,7 @@ TEST(GetHeaderValueTest, DefaultValue) {
|
|
|
|
|
|
|
|
|
|
TEST(GetHeaderValueTest, DefaultValueInt) {
|
|
|
|
|
Headers headers = {{"Dummy", "Dummy"}};
|
|
|
|
|
auto val =
|
|
|
|
|
detail::get_header_value<uint64_t>(headers, "Content-Length", 0, 100);
|
|
|
|
|
auto val = detail::get_header_value_u64(headers, "Content-Length", 0, 100);
|
|
|
|
|
EXPECT_EQ(100ull, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -241,8 +240,7 @@ TEST(GetHeaderValueTest, SetContent) {
|
|
|
|
|
|
|
|
|
|
TEST(GetHeaderValueTest, RegularValueInt) {
|
|
|
|
|
Headers headers = {{"Content-Length", "100"}, {"Dummy", "Dummy"}};
|
|
|
|
|
auto val =
|
|
|
|
|
detail::get_header_value<uint64_t>(headers, "Content-Length", 0, 0);
|
|
|
|
|
auto val = detail::get_header_value_u64(headers, "Content-Length", 0, 0);
|
|
|
|
|
EXPECT_EQ(100ull, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -444,7 +442,7 @@ TEST(HostnameToIPConversionTest, HTTPWatch_Online) {
|
|
|
|
|
auto host = "www.httpwatch.com";
|
|
|
|
|
|
|
|
|
|
auto ip = hosted_at(host);
|
|
|
|
|
EXPECT_EQ("191.236.16.12", ip);
|
|
|
|
|
EXPECT_EQ("23.96.13.243", ip);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> addrs;
|
|
|
|
|
hosted_at(host, addrs);
|
|
|
|
@@ -1016,7 +1014,7 @@ TEST(UrlWithSpace, Redirect_Online) {
|
|
|
|
|
auto res = cli.Get("/files/2595/310/Neat 1.4-17.jar");
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(200, res->status);
|
|
|
|
|
EXPECT_EQ(18527U, res->get_header_value<uint64_t>("Content-Length"));
|
|
|
|
|
EXPECT_EQ(18527U, res->get_header_value_u64("Content-Length"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
@@ -1090,12 +1088,8 @@ TEST(RedirectToDifferentPort, Redirect) {
|
|
|
|
|
ASSERT_FALSE(svr1.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
while (!svr1.is_running() || !svr2.is_running()) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr1.wait_until_ready();
|
|
|
|
|
svr2.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", svr2_port);
|
|
|
|
|
cli.set_follow_location(true);
|
|
|
|
@@ -1127,9 +1121,6 @@ TEST(RedirectFromPageWithContent, Redirect) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
cli.set_follow_location(true);
|
|
|
|
@@ -1195,9 +1186,6 @@ TEST(RedirectFromPageWithContentIP6, Redirect) {
|
|
|
|
|
ASSERT_LT(milliseconds, 5000U);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli("http://[::1]:1234");
|
|
|
|
|
cli.set_follow_location(true);
|
|
|
|
@@ -1248,8 +1236,7 @@ TEST(PathUrlEncodeTest, PathUrlEncode) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -1279,8 +1266,7 @@ TEST(BindServerTest, DISABLED_BindDualStack) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli("127.0.0.1", PORT);
|
|
|
|
@@ -1351,8 +1337,7 @@ TEST(ErrorHandlerTest, ContentLength) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -1393,8 +1378,7 @@ TEST(ExceptionHandlerTest, ContentLength) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 10; i++) {
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -1434,8 +1418,7 @@ TEST(NoContentTest, ContentLength) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -1485,8 +1468,7 @@ TEST(RoutingHandlerTest, PreRoutingHandler) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
|
|
|
@@ -1554,8 +1536,7 @@ TEST(InvalidFormatTest, StatusCode) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -1579,7 +1560,7 @@ TEST(URLFragmentTest, WithFragment) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -1594,6 +1575,46 @@ TEST(URLFragmentTest, WithFragment) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HeaderWriter, SetHeaderWriter) {
|
|
|
|
|
Server svr;
|
|
|
|
|
|
|
|
|
|
svr.set_header_writer([](Stream &strm, Headers &hdrs) {
|
|
|
|
|
hdrs.emplace("CustomServerHeader", "CustomServerValue");
|
|
|
|
|
return detail::write_headers(strm, hdrs);
|
|
|
|
|
});
|
|
|
|
|
svr.Get("/hi", [](const Request &req, Response &res) {
|
|
|
|
|
auto it = req.headers.find("CustomClientHeader");
|
|
|
|
|
EXPECT_TRUE(it != req.headers.end());
|
|
|
|
|
EXPECT_EQ(it->second, "CustomClientValue");
|
|
|
|
|
res.set_content("Hello World!\n", "text/plain");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto thread = std::thread([&]() { svr.listen(HOST, PORT); });
|
|
|
|
|
auto se = detail::scope_exit([&] {
|
|
|
|
|
svr.stop();
|
|
|
|
|
thread.join();
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
|
cli.set_header_writer([](Stream &strm, Headers &hdrs) {
|
|
|
|
|
hdrs.emplace("CustomClientHeader", "CustomClientValue");
|
|
|
|
|
return detail::write_headers(strm, hdrs);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto res = cli.Get("/hi");
|
|
|
|
|
EXPECT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(200, res->status);
|
|
|
|
|
|
|
|
|
|
auto it = res->headers.find("CustomServerHeader");
|
|
|
|
|
EXPECT_TRUE(it != res->headers.end());
|
|
|
|
|
EXPECT_EQ(it->second, "CustomServerValue");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ServerTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
ServerTest()
|
|
|
|
@@ -2167,9 +2188,7 @@ protected:
|
|
|
|
|
|
|
|
|
|
t_ = thread([&]() { ASSERT_TRUE(svr_.listen(HOST, PORT)); });
|
|
|
|
|
|
|
|
|
|
while (!svr_.is_running()) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
}
|
|
|
|
|
svr_.wait_until_ready();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
@@ -2501,6 +2520,55 @@ TEST_F(ServerTest, StaticFileRange) {
|
|
|
|
|
EXPECT_EQ(std::string("cd"), res->body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, StaticFileRanges) {
|
|
|
|
|
auto res =
|
|
|
|
|
cli_.Get("/dir/test.abcde", {{make_range_header({{1, 2}, {4, -1}})}});
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(206, res->status);
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
|
res->get_header_value("Content-Type")
|
|
|
|
|
.find(
|
|
|
|
|
"multipart/byteranges; boundary=--cpp-httplib-multipart-data-") ==
|
|
|
|
|
0);
|
|
|
|
|
EXPECT_EQ("265", res->get_header_value("Content-Length"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, StaticFileRangeHead) {
|
|
|
|
|
auto res = cli_.Head("/dir/test.abcde", {{make_range_header({{2, 3}})}});
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(206, res->status);
|
|
|
|
|
EXPECT_EQ("text/abcde", res->get_header_value("Content-Type"));
|
|
|
|
|
EXPECT_EQ("2", res->get_header_value("Content-Length"));
|
|
|
|
|
EXPECT_EQ(true, res->has_header("Content-Range"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, StaticFileRangeBigFile) {
|
|
|
|
|
auto res = cli_.Get("/dir/1MB.txt", {{make_range_header({{-1, 5}})}});
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(206, res->status);
|
|
|
|
|
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
|
|
|
|
|
EXPECT_EQ("5", res->get_header_value("Content-Length"));
|
|
|
|
|
EXPECT_EQ(true, res->has_header("Content-Range"));
|
|
|
|
|
EXPECT_EQ("LAST\n", res->body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, StaticFileRangeBigFile2) {
|
|
|
|
|
auto res = cli_.Get("/dir/1MB.txt", {{make_range_header({{1, 4097}})}});
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(206, res->status);
|
|
|
|
|
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
|
|
|
|
|
EXPECT_EQ("4097", res->get_header_value("Content-Length"));
|
|
|
|
|
EXPECT_EQ(true, res->has_header("Content-Range"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, StaticFileBigFile) {
|
|
|
|
|
auto res = cli_.Get("/dir/1MB.txt");
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(200, res->status);
|
|
|
|
|
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
|
|
|
|
|
EXPECT_EQ("1048576", res->get_header_value("Content-Length"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, InvalidBaseDirMount) {
|
|
|
|
|
EXPECT_EQ(false, svr_.set_mount_point("invalid_mount_point", "./www3"));
|
|
|
|
|
}
|
|
|
|
@@ -2886,9 +2954,9 @@ TEST_F(ServerTest, GetStreamedWithRangeMultipart) {
|
|
|
|
|
cli_.Get("/streamed-with-range", {{make_range_header({{1, 2}, {4, 5}})}});
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(206, res->status);
|
|
|
|
|
EXPECT_EQ("269", res->get_header_value("Content-Length"));
|
|
|
|
|
EXPECT_EQ("267", res->get_header_value("Content-Length"));
|
|
|
|
|
EXPECT_EQ(false, res->has_header("Content-Range"));
|
|
|
|
|
EXPECT_EQ(269U, res->body.size());
|
|
|
|
|
EXPECT_EQ(267U, res->body.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, GetStreamedEndless) {
|
|
|
|
@@ -2978,9 +3046,9 @@ TEST_F(ServerTest, GetWithRangeMultipart) {
|
|
|
|
|
auto res = cli_.Get("/with-range", {{make_range_header({{1, 2}, {4, 5}})}});
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(206, res->status);
|
|
|
|
|
EXPECT_EQ("269", res->get_header_value("Content-Length"));
|
|
|
|
|
EXPECT_EQ("267", res->get_header_value("Content-Length"));
|
|
|
|
|
EXPECT_EQ(false, res->has_header("Content-Range"));
|
|
|
|
|
EXPECT_EQ(269U, res->body.size());
|
|
|
|
|
EXPECT_EQ(267U, res->body.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
|
|
|
|
@@ -3247,7 +3315,7 @@ TEST_F(ServerTest, PutLargeFileWithGzip2) {
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
|
EXPECT_EQ(200, res->status);
|
|
|
|
|
EXPECT_EQ(LARGE_DATA, res->body);
|
|
|
|
|
EXPECT_EQ(101942u, res.get_request_header_value<uint64_t>("Content-Length"));
|
|
|
|
|
EXPECT_EQ(101942u, res.get_request_header_value_u64("Content-Length"));
|
|
|
|
|
EXPECT_EQ("gzip", res.get_request_header_value("Content-Encoding"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -4135,9 +4203,6 @@ TEST(MountTest, Unmount) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
|
|
|
|
|
svr.set_mount_point("/mount2", "./www2");
|
|
|
|
@@ -4188,9 +4253,6 @@ TEST(ExceptionTest, ThrowExceptionInHandler) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
@@ -4232,9 +4294,6 @@ TEST(KeepAliveTest, ReadTimeout) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
cli.set_keep_alive(true);
|
|
|
|
|
cli.set_read_timeout(std::chrono::seconds(1));
|
|
|
|
@@ -4264,7 +4323,7 @@ TEST(KeepAliveTest, Issue1041) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
|
cli.set_keep_alive(true);
|
|
|
|
@@ -4297,7 +4356,7 @@ TEST(KeepAliveTest, SSLClientReconnection) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli(HOST, PORT);
|
|
|
|
|
cli.enable_server_certificate_verification(false);
|
|
|
|
@@ -4360,9 +4419,6 @@ TEST(ClientProblemDetectionTest, ContentProvider) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
@@ -4400,9 +4456,6 @@ TEST(ErrorHandlerWithContentProviderTest, ErrorHandler) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
|
|
|
|
|
auto res = cli.Get("/");
|
|
|
|
@@ -4411,6 +4464,43 @@ TEST(ErrorHandlerWithContentProviderTest, ErrorHandler) {
|
|
|
|
|
EXPECT_EQ("helloworld", res->body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(LongPollingTest, ClientCloseDetection) {
|
|
|
|
|
Server svr;
|
|
|
|
|
|
|
|
|
|
svr.Get("/events", [&](const Request & /*req*/, Response &res) {
|
|
|
|
|
res.set_chunked_content_provider(
|
|
|
|
|
"text/plain", [](std::size_t const, DataSink &sink) -> bool {
|
|
|
|
|
EXPECT_TRUE(sink.is_writable()); // the socket is alive
|
|
|
|
|
sink.os << "hello";
|
|
|
|
|
|
|
|
|
|
auto count = 10;
|
|
|
|
|
while (count > 0 && sink.is_writable()) {
|
|
|
|
|
this_thread::sleep_for(chrono::milliseconds(10));
|
|
|
|
|
}
|
|
|
|
|
EXPECT_FALSE(sink.is_writable()); // the socket is closed
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
|
|
|
|
|
auto se = detail::scope_exit([&] {
|
|
|
|
|
svr.stop();
|
|
|
|
|
listen_thread.join();
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
|
|
|
|
|
auto res = cli.Get("/events", [&](const char *data, size_t data_length) {
|
|
|
|
|
EXPECT_EQ("hello", string(data, data_length));
|
|
|
|
|
return false; // close the socket immediately.
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(GetWithParametersTest, GetWithParameters) {
|
|
|
|
|
Server svr;
|
|
|
|
|
|
|
|
|
@@ -4446,7 +4536,6 @@ TEST(GetWithParametersTest, GetWithParameters) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -4505,7 +4594,6 @@ TEST(GetWithParametersTest, GetWithParameters2) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
|
|
|
|
@@ -4573,7 +4661,6 @@ TEST(ServerDefaultHeadersTest, DefaultHeaders) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli("localhost", PORT);
|
|
|
|
|
|
|
|
|
@@ -4608,9 +4695,6 @@ TEST(KeepAliveTest, ReadTimeoutSSL) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
SSLClient cli("localhost", PORT);
|
|
|
|
|
cli.enable_server_certificate_verification(false);
|
|
|
|
|
cli.set_keep_alive(true);
|
|
|
|
@@ -4649,9 +4733,7 @@ protected:
|
|
|
|
|
t_ = thread(
|
|
|
|
|
[&]() { ASSERT_TRUE(svr_.listen(std::string(), PORT, AI_PASSIVE)); });
|
|
|
|
|
|
|
|
|
|
while (!svr_.is_running()) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
}
|
|
|
|
|
svr_.wait_until_ready();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
@@ -4688,9 +4770,7 @@ protected:
|
|
|
|
|
ASSERT_TRUE(svr_.listen_after_bind());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
while (!svr_.is_running()) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
}
|
|
|
|
|
svr_.wait_until_ready();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
@@ -4731,9 +4811,7 @@ protected:
|
|
|
|
|
|
|
|
|
|
t_ = thread([&]() { ASSERT_TRUE(svr_.listen(HOST, PORT)); });
|
|
|
|
|
|
|
|
|
|
while (!svr_.is_running()) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
}
|
|
|
|
|
svr_.wait_until_ready();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
@@ -4850,7 +4928,7 @@ TEST(SSLClientTest, ServerCertificateVerification4) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli("127.0.0.1", PORT);
|
|
|
|
|
cli.set_ca_cert_path(SERVER_CERT2_FILE);
|
|
|
|
@@ -4966,7 +5044,7 @@ TEST(SSLClientServerTest, ClientCertPresent) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli(HOST, PORT, CLIENT_CERT_FILE, CLIENT_PRIVATE_KEY_FILE);
|
|
|
|
|
cli.enable_server_certificate_verification(false);
|
|
|
|
@@ -5041,7 +5119,7 @@ TEST(SSLClientServerTest, MemoryClientCertPresent) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli(HOST, PORT, client_cert, client_private_key);
|
|
|
|
|
cli.enable_server_certificate_verification(false);
|
|
|
|
@@ -5072,7 +5150,7 @@ TEST(SSLClientServerTest, ClientCertMissing) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli(HOST, PORT);
|
|
|
|
|
auto res = cli.Get("/test");
|
|
|
|
@@ -5096,7 +5174,7 @@ TEST(SSLClientServerTest, TrustDirOptional) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli(HOST, PORT, CLIENT_CERT_FILE, CLIENT_PRIVATE_KEY_FILE);
|
|
|
|
|
cli.enable_server_certificate_verification(false);
|
|
|
|
@@ -5117,12 +5195,12 @@ TEST(SSLClientServerTest, SSLConnectTimeout) {
|
|
|
|
|
client_ca_cert_dir_path),
|
|
|
|
|
stop_(false) {}
|
|
|
|
|
|
|
|
|
|
bool stop_;
|
|
|
|
|
std::atomic_bool stop_;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool process_and_close_socket(socket_t /*sock*/) override {
|
|
|
|
|
// Don't create SSL context
|
|
|
|
|
while (!stop_) {
|
|
|
|
|
while (!stop_.load()) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@@ -5144,7 +5222,7 @@ TEST(SSLClientServerTest, SSLConnectTimeout) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli(HOST, PORT, CLIENT_CERT_FILE, CLIENT_PRIVATE_KEY_FILE);
|
|
|
|
|
cli.enable_server_certificate_verification(false);
|
|
|
|
@@ -5216,7 +5294,7 @@ TEST(SSLClientServerTest, CustomizeServerSSLCtx) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
SSLClient cli(HOST, PORT, CLIENT_CERT_FILE, CLIENT_PRIVATE_KEY_FILE);
|
|
|
|
|
cli.enable_server_certificate_verification(false);
|
|
|
|
@@ -5352,9 +5430,10 @@ TEST(ServerLargeContentTest, DISABLED_SendLargeContent) {
|
|
|
|
|
ASSERT_TRUE(content);
|
|
|
|
|
|
|
|
|
|
Server svr;
|
|
|
|
|
svr.Get("/foo", [=](const httplib::Request &req, httplib::Response &resp) {
|
|
|
|
|
resp.set_content(content, content_size, "application/octet-stream");
|
|
|
|
|
});
|
|
|
|
|
svr.Get("/foo",
|
|
|
|
|
[=](const httplib::Request & /*req*/, httplib::Response &res) {
|
|
|
|
|
res.set_content(content, content_size, "application/octet-stream");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto listen_thread = std::thread([&svr]() { svr.listen(HOST, PORT); });
|
|
|
|
|
auto se = detail::scope_exit([&] {
|
|
|
|
@@ -5366,9 +5445,6 @@ TEST(ServerLargeContentTest, DISABLED_SendLargeContent) {
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
// Give GET time to get a few messages.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
|
auto res = cli.Get("/foo");
|
|
|
|
|
ASSERT_TRUE(res);
|
|
|
|
@@ -5503,7 +5579,8 @@ TEST(HttpToHttpsRedirectTest, CertFile) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
ssl_svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
Client cli("127.0.0.1", PORT);
|
|
|
|
|
cli.set_ca_cert_path(SERVER_CERT2_FILE);
|
|
|
|
@@ -5559,7 +5636,6 @@ TEST(MultipartFormDataTest, LargeData) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::string data(1024 * 1024 * 2, '.');
|
|
|
|
@@ -5707,7 +5783,6 @@ TEST(MultipartFormDataTest, DataProviderItems) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli("https://localhost:8080");
|
|
|
|
@@ -5909,7 +5984,6 @@ TEST(MultipartFormDataTest, PostCustomBoundary) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::string data(1024 * 1024 * 2, '.');
|
|
|
|
@@ -5931,9 +6005,6 @@ TEST(MultipartFormDataTest, PostCustomBoundary) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MultipartFormDataTest, PostInvalidBoundaryChars) {
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
std::string data(1024 * 1024 * 2, '&');
|
|
|
|
|
std::stringstream buffer;
|
|
|
|
|
buffer << data;
|
|
|
|
@@ -5996,7 +6067,6 @@ TEST(MultipartFormDataTest, PutFormData) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::string data(1024 * 1024 * 2, '&');
|
|
|
|
@@ -6061,7 +6131,6 @@ TEST(MultipartFormDataTest, PutFormDataCustomBoundary) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::string data(1024 * 1024 * 2, '&');
|
|
|
|
@@ -6083,9 +6152,6 @@ TEST(MultipartFormDataTest, PutFormDataCustomBoundary) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MultipartFormDataTest, PutInvalidBoundaryChars) {
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
|
|
|
std::string data(1024 * 1024 * 2, '&');
|
|
|
|
|
std::stringstream buffer;
|
|
|
|
|
buffer << data;
|
|
|
|
@@ -6155,7 +6221,7 @@ TEST(MultipartFormDataTest, AlternateFilename) {
|
|
|
|
|
"\r\n"
|
|
|
|
|
"text default\r\n"
|
|
|
|
|
"----------\r\n"
|
|
|
|
|
"Content-Disposition: form-data; filename*=\"UTF-8''\%41.txt\"; "
|
|
|
|
|
"Content-Disposition: form-data; filename*=\"UTF-8''%41.txt\"; "
|
|
|
|
|
"filename=\"a.txt\"; name=\"file1\"\r\n"
|
|
|
|
|
"Content-Type: text/plain\r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
@@ -6414,7 +6480,7 @@ TEST(RedirectTest, RedirectToUrlWithQueryParameters) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
@@ -6460,7 +6526,7 @@ TEST(VulnerabilityTest, CRLFInjection) {
|
|
|
|
|
ASSERT_FALSE(svr.is_running());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
svr.wait_until_ready();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Client cli(HOST, PORT);
|
|
|
|
|