@@ -3015,8 +3015,10 @@ TEST(GzipDecompressor, ChunkedDecompression) {
3015
3015
httplib::detail::gzip_compressor compressor;
3016
3016
bool result = compressor.compress (
3017
3017
data.data (), data.size (),
3018
- /* last=*/ true , [&](const char *compressed_data_chunk, size_t compressed_data_size) {
3019
- compressed_data.insert (compressed_data.size (), compressed_data_chunk, compressed_data_size);
3018
+ /* last=*/ true ,
3019
+ [&](const char *compressed_data_chunk, size_t compressed_data_size) {
3020
+ compressed_data.insert (compressed_data.size (), compressed_data_chunk,
3021
+ compressed_data_size);
3020
3022
return true ;
3021
3023
});
3022
3024
ASSERT_TRUE (result);
@@ -3035,8 +3037,11 @@ TEST(GzipDecompressor, ChunkedDecompression) {
3035
3037
std::min (compressed_data.size () - chunk_begin, chunk_size);
3036
3038
bool result = decompressor.decompress (
3037
3039
compressed_data.data () + chunk_begin, current_chunk_size,
3038
- [&](const char *decompressed_data_chunk, size_t decompressed_data_chunk_size) {
3039
- decompressed_data.insert (decompressed_data.size (), decompressed_data_chunk, decompressed_data_chunk_size);
3040
+ [&](const char *decompressed_data_chunk,
3041
+ size_t decompressed_data_chunk_size) {
3042
+ decompressed_data.insert (decompressed_data.size (),
3043
+ decompressed_data_chunk,
3044
+ decompressed_data_chunk_size);
3040
3045
return true ;
3041
3046
});
3042
3047
ASSERT_TRUE (result);
@@ -4974,5 +4979,48 @@ TEST(MultipartFormDataTest, LargeData) {
4974
4979
svr.stop ();
4975
4980
t.join ();
4976
4981
}
4982
+
4983
+ TEST (MultipartFormDataTest, WithPreamble) {
4984
+ Server svr;
4985
+ svr.Post (" /post" , [&](const Request &req, Response &res) {
4986
+ res.set_content (" ok" , " text/plain" );
4987
+ });
4988
+
4989
+ thread t = thread ([&] { svr.listen (HOST, PORT); });
4990
+ while (!svr.is_running ()) {
4991
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
4992
+ }
4993
+
4994
+ const std::string body =
4995
+ " This is the preamble. It is to be ignored, though it\r\n "
4996
+ " is a handy place for composition agents to include an\r\n "
4997
+ " explanatory note to non-MIME conformant readers.\r\n "
4998
+ " \r\n "
4999
+ " \r\n "
5000
+ " --simple boundary\r\n "
5001
+ " Content-Disposition: form-data; name=\" field1\"\r\n "
5002
+ " \r\n "
5003
+ " value1\r\n "
5004
+ " --simple boundary\r\n "
5005
+ " Content-Disposition: form-data; name=\" field2\" ; "
5006
+ " filename=\" example.txt\"\r\n "
5007
+ " \r\n "
5008
+ " value2\r\n "
5009
+ " --simple boundary--\r\n "
5010
+ " This is the epilogue. It is also to be ignored.\r\n " ;
5011
+
5012
+ std::string content_type =
5013
+ R"( multipart/form-data; boundary="simple boundary")" ;
5014
+
5015
+ Client cli (HOST, PORT);
5016
+ auto res = cli.Post (" /post" , body, content_type.c_str ());
5017
+
5018
+ ASSERT_TRUE (res);
5019
+ EXPECT_EQ (200 , res->status );
5020
+
5021
+ svr.stop ();
5022
+ t.join ();
5023
+ }
5024
+
4977
5025
#endif
4978
5026
0 commit comments