|
|
@@ -1,6 +1,7 @@
|
|
|
#include <httplib.h>
|
|
|
#include <signal.h>
|
|
|
|
|
|
+#include <curl/curl.h>
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
#include <atomic>
|
|
|
@@ -12,6 +13,7 @@
|
|
|
#include <stdexcept>
|
|
|
#include <thread>
|
|
|
#include <type_traits>
|
|
|
+#include <vector>
|
|
|
|
|
|
#define SERVER_CERT_FILE "./cert.pem"
|
|
|
#define SERVER_CERT2_FILE "./cert2.pem"
|
|
|
@@ -7604,3 +7606,101 @@ TEST(DirtyDataRequestTest, HeadFieldValueContains_CR_LF_NUL) {
|
|
|
Client cli(HOST, PORT);
|
|
|
cli.Get("/test", {{"Test", "_\n\r_\n\r_"}});
|
|
|
}
|
|
|
+
|
|
|
+TEST(Expect100ContinueTest, ServerClosesConnection) {
|
|
|
+ static constexpr char reject[] = "Unauthorized";
|
|
|
+ static constexpr char accept[] = "Upload accepted";
|
|
|
+ constexpr size_t total_size = 10 * 1024 * 1024 * 1024ULL;
|
|
|
+
|
|
|
+ Server svr;
|
|
|
+
|
|
|
+ svr.set_expect_100_continue_handler([](const Request &req, Response &res) {
|
|
|
+ res.status = StatusCode::Unauthorized_401;
|
|
|
+ res.set_content(reject, "text/plain");
|
|
|
+ return res.status;
|
|
|
+ });
|
|
|
+ svr.Post("/", [&](const Request & /*req*/, Response &res) {
|
|
|
+ res.set_content(accept, "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();
|
|
|
+
|
|
|
+ {
|
|
|
+ const auto curl = std::unique_ptr<CURL, decltype(&curl_easy_cleanup)>{
|
|
|
+ curl_easy_init(), &curl_easy_cleanup};
|
|
|
+ ASSERT_NE(curl, nullptr);
|
|
|
+
|
|
|
+ curl_easy_setopt(curl.get(), CURLOPT_URL, HOST);
|
|
|
+ curl_easy_setopt(curl.get(), CURLOPT_PORT, PORT);
|
|
|
+ curl_easy_setopt(curl.get(), CURLOPT_POST, 1L);
|
|
|
+ auto list = std::unique_ptr<curl_slist, decltype(&curl_slist_free_all)>{
|
|
|
+ curl_slist_append(nullptr, "Content-Type: application/octet-stream"),
|
|
|
+ &curl_slist_free_all};
|
|
|
+ ASSERT_NE(list, nullptr);
|
|
|
+ curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, list.get());
|
|
|
+
|
|
|
+ struct read_data {
|
|
|