Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Fix not properly handling data from multipart-form POST (#739).
Fix not cleaning up request parameters when generating profiles (#741).
  • Loading branch information
tindy2013 committed Apr 8, 2024
1 parent b9ad0c2 commit 0c85747
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/handler/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,10 +1362,10 @@ int simpleGenerator()

string_multimap allItems;
std::string proxy = parseProxy(global.proxySubscription);
Request request;
Response response;
for(std::string &x : sections)
{
Request request;
Response response;
response.status_code = 200;
//std::cerr<<"Generating artifact '"<<x<<"'...\n";
writeLog(0, "Generating artifact '" + x + "'...", LOG_LEVEL_INFO);
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ int main(int argc, char *argv[])
}
}
std::string type = getUrlArg(request.argument, "type");
if(type == "form")
fileWrite(global.prefPath, getFormData(request.postdata), true);
else if(type == "direct")
if(type == "form" || type == "direct")
{
fileWrite(global.prefPath, request.postdata, true);
}
else
{
response.status_code = 501;
Expand Down
19 changes: 13 additions & 6 deletions src/server/webserver_httplib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ static httplib::Server::Handler makeHandler(const responseRoute &rr)
req.headers.emplace(h.first.data(), h.second.data());
}
req.argument = request.params;
if (request.get_header_value("Content-Type") == "application/x-www-form-urlencoded")
if (request.method == "POST" || request.method == "PUT" || request.method == "PATCH")
{
req.postdata = urlDecode(request.body);
}
else
{
req.postdata = request.body;
if (request.is_multipart_form_data() && !request.files.empty())
{
req.postdata = request.files.begin()->second.content;
}
else if (request.get_header_value("Content-Type") == "application/x-www-form-urlencoded")
{
req.postdata = urlDecode(request.body);
}
else
{
req.postdata = request.body;
}
}
auto result = rr.rc(req, resp);
response.status = resp.status_code;
Expand Down

0 comments on commit 0c85747

Please sign in to comment.