-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Feature/multipart headers #2152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
320c64f
4ef3708
715d2ce
3a492c1
0bc40d6
8b70d51
3bc6e73
f4f2992
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8010,6 +8010,68 @@ TEST(MultipartFormDataTest, ContentLength) { | |
ASSERT_TRUE(send_request(1, req, &response)); | ||
ASSERT_EQ("200", response.substr(9, 3)); | ||
} | ||
|
||
TEST(MultipartFormDataTest, AccessPartHeaders) { | ||
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); | ||
ASSERT_EQ(1, it->second.headers.count("Content-Length")); | ||
auto content_lenght = it->second.headers.find("CONTENT-length"); | ||
ASSERT_EQ("5", content_lenght->second); | ||
ASSERT_EQ(3, it->second.headers.size()); | ||
|
||
++it; | ||
ASSERT_EQ("text2", it->second.name); | ||
ASSERT_EQ("text2", it->second.content); | ||
auto &headers = it->second.headers; | ||
ASSERT_EQ(3, headers.size()); | ||
auto customHeader = headers.find("x-whatever"); | ||
kwach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ASSERT_TRUE(customHeader != headers.end()); | ||
ASSERT_NE("customvalue", customHeader->second); | ||
ASSERT_EQ("CustomValue", customHeader->second); | ||
ASSERT_TRUE(headers.find("X-Test") == headers.end()); // text1 header | ||
|
||
handled = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reused code from the MultipartFormDataTest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then there is
in
|
||
}); | ||
|
||
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: 232\r\n" | ||
"\r\n----------\r\n" | ||
"Content-Disposition: form-data; name=\"text1\"\r\n" | ||
"Content-Length: 5\r\n" | ||
"X-Test: 1\r\n" | ||
"\r\n" | ||
"text1" | ||
"\r\n----------\r\n" | ||
"Content-Disposition: form-data; name=\"text2\"\r\n" | ||
"Content-Type: text/plain\r\n" | ||
"X-Whatever: CustomValue\r\n" | ||
"\r\n" | ||
"text2" | ||
"\r\n------------\r\n" | ||
"That should be disregarded. Not even read"; | ||
|
||
std::string response; | ||
ASSERT_TRUE(send_request(1, req, &response)); | ||
ASSERT_EQ("200", response.substr(9, 3)); | ||
} | ||
#endif | ||
|
||
TEST(TaskQueueTest, IncreaseAtomicInteger) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.