Skip to content

Commit e9575bc

Browse files
authored
don't replace plus with space in headers (yhirose#649)
* don't replace plus with space in headers * fixed forward handling with changed header parsing * add test for boundaries containing plus chars
1 parent 308aeb1 commit e9575bc

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

httplib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ inline bool parse_header(const char *beg, const char *end, T fn) {
24642464
}
24652465

24662466
if (p < end) {
2467-
fn(std::string(beg, key_end), decode_url(std::string(p, end), true));
2467+
fn(std::string(beg, key_end), decode_url(std::string(p, end), false));
24682468
return true;
24692469
}
24702470

@@ -4768,7 +4768,7 @@ inline bool ClientImpl::redirect(const Request &req, Response &res) {
47684768
return false;
47694769
}
47704770

4771-
auto location = res.get_header_value("location");
4771+
auto location = detail::decode_url(res.get_header_value("location"), true);
47724772
if (location.empty()) { return false; }
47734773

47744774
const static std::regex re(

test/test.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,6 +2323,41 @@ TEST_F(ServerTest, PostMulitpartFilsContentReceiver) {
23232323
EXPECT_EQ(200, res->status);
23242324
}
23252325

2326+
TEST_F(ServerTest, PostMulitpartPlusBoundary) {
2327+
MultipartFormDataItems items = {
2328+
{"text1", "text default", "", ""},
2329+
{"text2", "aωb", "", ""},
2330+
{"file1", "h\ne\n\nl\nl\no\n", "hello.txt", "text/plain"},
2331+
{"file2", "{\n \"world\", true\n}\n", "world.json", "application/json"},
2332+
{"file3", "", "", "application/octet-stream"},
2333+
};
2334+
2335+
auto boundary = std::string("+++++");
2336+
2337+
std::string body;
2338+
2339+
for (const auto &item : items) {
2340+
body += "--" + boundary + "\r\n";
2341+
body += "Content-Disposition: form-data; name=\"" + item.name + "\"";
2342+
if (!item.filename.empty()) {
2343+
body += "; filename=\"" + item.filename + "\"";
2344+
}
2345+
body += "\r\n";
2346+
if (!item.content_type.empty()) {
2347+
body += "Content-Type: " + item.content_type + "\r\n";
2348+
}
2349+
body += "\r\n";
2350+
body += item.content + "\r\n";
2351+
}
2352+
body += "--" + boundary + "--\r\n";
2353+
2354+
std::string content_type = "multipart/form-data; boundary=" + boundary;
2355+
auto res = cli_.Post("/content_receiver", body, content_type.c_str());
2356+
2357+
ASSERT_TRUE(res);
2358+
EXPECT_EQ(200, res->status);
2359+
}
2360+
23262361
TEST_F(ServerTest, PostContentReceiverGzip) {
23272362
cli_.set_compress(true);
23282363
auto res = cli_.Post("/content_receiver", "content", "text/plain");

0 commit comments

Comments
 (0)