mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
don't replace plus with space in headers (#649)
* don't replace plus with space in headers * fixed forward handling with changed header parsing * add test for boundaries containing plus chars
This commit is contained in:
parent
308aeb187b
commit
e9575bcb78
2 changed files with 37 additions and 2 deletions
|
@ -2464,7 +2464,7 @@ inline bool parse_header(const char *beg, const char *end, T fn) {
|
|||
}
|
||||
|
||||
if (p < end) {
|
||||
fn(std::string(beg, key_end), decode_url(std::string(p, end), true));
|
||||
fn(std::string(beg, key_end), decode_url(std::string(p, end), false));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4768,7 +4768,7 @@ inline bool ClientImpl::redirect(const Request &req, Response &res) {
|
|||
return false;
|
||||
}
|
||||
|
||||
auto location = res.get_header_value("location");
|
||||
auto location = detail::decode_url(res.get_header_value("location"), true);
|
||||
if (location.empty()) { return false; }
|
||||
|
||||
const static std::regex re(
|
||||
|
|
35
test/test.cc
35
test/test.cc
|
@ -2323,6 +2323,41 @@ TEST_F(ServerTest, PostMulitpartFilsContentReceiver) {
|
|||
EXPECT_EQ(200, res->status);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, PostMulitpartPlusBoundary) {
|
||||
MultipartFormDataItems items = {
|
||||
{"text1", "text default", "", ""},
|
||||
{"text2", "aωb", "", ""},
|
||||
{"file1", "h\ne\n\nl\nl\no\n", "hello.txt", "text/plain"},
|
||||
{"file2", "{\n \"world\", true\n}\n", "world.json", "application/json"},
|
||||
{"file3", "", "", "application/octet-stream"},
|
||||
};
|
||||
|
||||
auto boundary = std::string("+++++");
|
||||
|
||||
std::string body;
|
||||
|
||||
for (const auto &item : items) {
|
||||
body += "--" + boundary + "\r\n";
|
||||
body += "Content-Disposition: form-data; name=\"" + item.name + "\"";
|
||||
if (!item.filename.empty()) {
|
||||
body += "; filename=\"" + item.filename + "\"";
|
||||
}
|
||||
body += "\r\n";
|
||||
if (!item.content_type.empty()) {
|
||||
body += "Content-Type: " + item.content_type + "\r\n";
|
||||
}
|
||||
body += "\r\n";
|
||||
body += item.content + "\r\n";
|
||||
}
|
||||
body += "--" + boundary + "--\r\n";
|
||||
|
||||
std::string content_type = "multipart/form-data; boundary=" + boundary;
|
||||
auto res = cli_.Post("/content_receiver", body, content_type.c_str());
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(200, res->status);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, PostContentReceiverGzip) {
|
||||
cli_.set_compress(true);
|
||||
auto res = cli_.Post("/content_receiver", "content", "text/plain");
|
||||
|
|
Loading…
Reference in a new issue