Added 'compress' option to POST, PUT and PATCH.

This commit is contained in:
yhirose 2019-10-25 11:46:12 -04:00
parent 380f725713
commit bea3ebd7af
2 changed files with 69 additions and 92 deletions

View file

@ -1549,56 +1549,14 @@ TEST_F(ServerTest, NoGzipWithContentReceiver) {
}
TEST_F(ServerTest, MultipartFormDataGzip) {
Request req;
req.method = "POST";
req.path = "/gzipmultipart";
MultipartFormDataItems items = {
{"key1", "test", "", ""},
{"key2", "--abcdefg123", "", ""},
};
std::string host_and_port;
host_and_port += HOST;
host_and_port += ":";
host_and_port += std::to_string(PORT);
auto res = cli_.Post("/gzipmultipart", items, true);
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);
ASSERT_TRUE(res != nullptr);
EXPECT_EQ(200, res->status);
}
#endif