Fix #1619
This commit is contained in:
parent
aabf752a51
commit
ec87b04aff
@ -4267,9 +4267,9 @@ public:
|
|||||||
buf_erase(crlf_.size());
|
buf_erase(crlf_.size());
|
||||||
state_ = 1;
|
state_ = 1;
|
||||||
} else {
|
} else {
|
||||||
if (dash_crlf_.size() > buf_size()) { return true; }
|
if (dash_.size() > buf_size()) { return true; }
|
||||||
if (buf_start_with(dash_crlf_)) {
|
if (buf_start_with(dash_)) {
|
||||||
buf_erase(dash_crlf_.size());
|
buf_erase(dash_.size());
|
||||||
is_valid_ = true;
|
is_valid_ = true;
|
||||||
buf_erase(buf_size()); // Remove epilogue
|
buf_erase(buf_size()); // Remove epilogue
|
||||||
} else {
|
} else {
|
||||||
@ -4302,7 +4302,6 @@ private:
|
|||||||
|
|
||||||
const std::string dash_ = "--";
|
const std::string dash_ = "--";
|
||||||
const std::string crlf_ = "\r\n";
|
const std::string crlf_ = "\r\n";
|
||||||
const std::string dash_crlf_ = "--\r\n";
|
|
||||||
std::string boundary_;
|
std::string boundary_;
|
||||||
std::string dash_boundary_crlf_;
|
std::string dash_boundary_crlf_;
|
||||||
std::string crlf_dash_boundary_;
|
std::string crlf_dash_boundary_;
|
||||||
|
51
test/test.cc
51
test/test.cc
@ -6106,6 +6106,8 @@ TEST(MultipartFormDataTest, PutInvalidBoundaryChars) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(MultipartFormDataTest, AlternateFilename) {
|
TEST(MultipartFormDataTest, AlternateFilename) {
|
||||||
|
auto handled = false;
|
||||||
|
|
||||||
Server svr;
|
Server svr;
|
||||||
svr.Post("/test", [&](const Request &req, Response &res) {
|
svr.Post("/test", [&](const Request &req, Response &res) {
|
||||||
ASSERT_EQ(3u, req.files.size());
|
ASSERT_EQ(3u, req.files.size());
|
||||||
@ -6130,6 +6132,8 @@ TEST(MultipartFormDataTest, AlternateFilename) {
|
|||||||
ASSERT_EQ("text default", it->second.content);
|
ASSERT_EQ("text default", it->second.content);
|
||||||
|
|
||||||
res.set_content("ok", "text/plain");
|
res.set_content("ok", "text/plain");
|
||||||
|
|
||||||
|
handled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
thread t = thread([&] { svr.listen(HOST, PORT); });
|
thread t = thread([&] { svr.listen(HOST, PORT); });
|
||||||
@ -6137,6 +6141,7 @@ TEST(MultipartFormDataTest, AlternateFilename) {
|
|||||||
svr.stop();
|
svr.stop();
|
||||||
t.join();
|
t.join();
|
||||||
ASSERT_FALSE(svr.is_running());
|
ASSERT_FALSE(svr.is_running());
|
||||||
|
ASSERT_TRUE(handled);
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.wait_until_ready();
|
svr.wait_until_ready();
|
||||||
@ -6168,6 +6173,52 @@ TEST(MultipartFormDataTest, AlternateFilename) {
|
|||||||
ASSERT_TRUE(send_request(1, req));
|
ASSERT_TRUE(send_request(1, req));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MultipartFormDataTest, CloseDelimiterWithoutCRLF) {
|
||||||
|
auto handled = false;
|
||||||
|
|
||||||
|
Server svr;
|
||||||
|
svr.Post("/test", [&](const Request &req, Response &) {
|
||||||
|
ASSERT_EQ(2u, req.files.size());
|
||||||
|
|
||||||
|
auto it = req.files.begin();
|
||||||
|
ASSERT_EQ("text1", it->second.name);
|
||||||
|
ASSERT_EQ("text1", it->second.content);
|
||||||
|
|
||||||
|
++it;
|
||||||
|
ASSERT_EQ("text2", it->second.name);
|
||||||
|
ASSERT_EQ("text2", it->second.content);
|
||||||
|
|
||||||
|
handled = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
thread t = thread([&] { svr.listen(HOST, PORT); });
|
||||||
|
auto se = detail::scope_exit([&] {
|
||||||
|
svr.stop();
|
||||||
|
t.join();
|
||||||
|
ASSERT_FALSE(svr.is_running());
|
||||||
|
ASSERT_TRUE(handled);
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.wait_until_ready();
|
||||||
|
|
||||||
|
auto req = "POST /test HTTP/1.1\r\n"
|
||||||
|
"Content-Type: multipart/form-data;boundary=--------\r\n"
|
||||||
|
"Content-Length: 146\r\n"
|
||||||
|
"\r\n----------\r\n"
|
||||||
|
"Content-Disposition: form-data; name=\"text1\"\r\n"
|
||||||
|
"\r\n"
|
||||||
|
"text1"
|
||||||
|
"\r\n----------\r\n"
|
||||||
|
"Content-Disposition: form-data; name=\"text2\"\r\n"
|
||||||
|
"\r\n"
|
||||||
|
"text2"
|
||||||
|
"\r\n------------";
|
||||||
|
|
||||||
|
std::string resonse;
|
||||||
|
ASSERT_TRUE(send_request(1, req, &resonse));
|
||||||
|
ASSERT_EQ("200", resonse.substr(9, 3));
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user