|
@@ -325,6 +325,22 @@ protected:
|
|
|
.get("/nogzip", [&](const Request& /*req*/, Response& res) {
|
|
.get("/nogzip", [&](const Request& /*req*/, Response& res) {
|
|
|
res.set_content("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "application/octet-stream");
|
|
res.set_content("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "application/octet-stream");
|
|
|
})
|
|
})
|
|
|
|
|
+ .post("/gzipmultipart", [&](const Request& req, Response& /*res*/) {
|
|
|
|
|
+ EXPECT_EQ(2u, req.files.size());
|
|
|
|
|
+ ASSERT_TRUE(!req.has_file("???"));
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ const auto& file = req.get_file_value("key1");
|
|
|
|
|
+ EXPECT_EQ("", file.filename);
|
|
|
|
|
+ EXPECT_EQ("test", req.body.substr(file.offset, file.length));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ const auto& file = req.get_file_value("key2");
|
|
|
|
|
+ EXPECT_EQ("", file.filename);
|
|
|
|
|
+ EXPECT_EQ("--abcdefg123", req.body.substr(file.offset, file.length));
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
#endif
|
|
#endif
|
|
|
;
|
|
;
|
|
|
|
|
|
|
@@ -674,6 +690,59 @@ TEST_F(ServerTest, NoGzip)
|
|
|
EXPECT_EQ("100", res->get_header_value("Content-Length"));
|
|
EXPECT_EQ("100", res->get_header_value("Content-Length"));
|
|
|
EXPECT_EQ(200, res->status);
|
|
EXPECT_EQ(200, res->status);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ServerTest, MultipartFormDataGzip)
|
|
|
|
|
+{
|
|
|
|
|
+ Request req;
|
|
|
|
|
+ req.method = "POST";
|
|
|
|
|
+ req.path = "/gzipmultipart";
|
|
|
|
|
+
|
|
|
|
|
+ std::string host_and_port;
|
|
|
|
|
+ host_and_port += HOST;
|
|
|
|
|
+ host_and_port += ":";
|
|
|
|
|
+ host_and_port += std::to_string(PORT);
|
|
|
|
|
+
|
|
|
|
|
+ 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=------------------------fcba8368a9f48c0f");
|
|
|
|
|
+ req.headers.emplace("Content-Encoding", "gzip");
|
|
|
|
|
+
|
|
|
|
|
+ // compressed_body generated by creating input.txt to this file:
|
|
|
|
|
+ /*
|
|
|
|
|
+ --------------------------fcba8368a9f48c0f
|
|
|
|
|
+ Content-Disposition: form-data; name="key1"
|
|
|
|
|
+
|
|
|
|
|
+ test
|
|
|
|
|
+ --------------------------fcba8368a9f48c0f
|
|
|
|
|
+ Content-Disposition: form-data; name="key2"
|
|
|
|
|
+
|
|
|
|
|
+ --abcdefg123
|
|
|
|
|
+ --------------------------fcba8368a9f48c0f--
|
|
|
|
|
+ */
|
|
|
|
|
+ // then running unix2dos input.txt; gzip -9 -c input.txt | xxd -i.
|
|
|
|
|
+ uint8_t compressed_body[] = {
|
|
|
|
|
+ 0x1f, 0x8b, 0x08, 0x08, 0x48, 0xf1, 0xd4, 0x5a, 0x02, 0x03, 0x69, 0x6e,
|
|
|
|
|
+ 0x70, 0x75, 0x74, 0x2e, 0x74, 0x78, 0x74, 0x00, 0xd3, 0xd5, 0xc5, 0x05,
|
|
|
|
|
+ 0xd2, 0x92, 0x93, 0x12, 0x2d, 0x8c, 0xcd, 0x2c, 0x12, 0x2d, 0xd3, 0x4c,
|
|
|
|
|
+ 0x2c, 0x92, 0x0d, 0xd2, 0x78, 0xb9, 0x9c, 0xf3, 0xf3, 0x4a, 0x52, 0xf3,
|
|
|
|
|
+ 0x4a, 0x74, 0x5d, 0x32, 0x8b, 0x0b, 0xf2, 0x8b, 0x33, 0x4b, 0x32, 0xf3,
|
|
|
|
|
+ 0xf3, 0xac, 0x14, 0xd2, 0xf2, 0x8b, 0x72, 0x75, 0x53, 0x12, 0x4b, 0x12,
|
|
|
|
|
+ 0xad, 0x15, 0xf2, 0x12, 0x73, 0x53, 0x6d, 0x95, 0xb2, 0x53, 0x2b, 0x0d,
|
|
|
|
|
+ 0x95, 0x78, 0xb9, 0x78, 0xb9, 0x4a, 0x52, 0x8b, 0x4b, 0x78, 0xb9, 0x74,
|
|
|
|
|
+ 0x69, 0x61, 0x81, 0x11, 0xd8, 0x02, 0x5d, 0xdd, 0xc4, 0xa4, 0xe4, 0x94,
|
|
|
|
|
+ 0xd4, 0xb4, 0x74, 0x43, 0x23, 0x63, 0x52, 0x2c, 0xd2, 0xd5, 0xe5, 0xe5,
|
|
|
|
|
+ 0x02, 0x00, 0xff, 0x0e, 0x72, 0xdf, 0xf8, 0x00, 0x00, 0x00
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ req.body = std::string((char*)compressed_body, sizeof(compressed_body) / sizeof(compressed_body[0]));
|
|
|
|
|
+
|
|
|
|
|
+ auto res = std::make_shared<Response>();
|
|
|
|
|
+ auto ret = cli_.send(req, *res);
|
|
|
|
|
+
|
|
|
|
|
+ ASSERT_TRUE(ret);
|
|
|
|
|
+ EXPECT_EQ(200, res->status);
|
|
|
|
|
+}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
class ServerTestWithAI_PASSIVE : public ::testing::Test {
|
|
class ServerTestWithAI_PASSIVE : public ::testing::Test {
|