Open JavierJF opened 2 years ago
For a POST or PUT request with body format application/x-www-form-urlencoded, if there are final parameters with key, but without value these are left unprocessed and not being reported as arguments in the request.
application/x-www-form-urlencoded
key
value
1 . Compile and launch this little code snippet:
#include <numeric> #include <string> #include <utility> #include "httpserver.hpp" using std::string; using std::pair; using namespace httpserver; class hello_world_resource : public http_resource { public: const std::shared_ptr<http_response> render(const http_request& req) { const auto& args = req.get_args(); string recv_args = std::accumulate(args.begin(), args.end(), string {}, [] (string& res, const pair<string,string>& arg) -> string { const string key_val_str { "\"" + arg.first + "\": " + "'" + arg.second + "'" }; if (res.empty()) { res = key_val_str; } else { res = res + ", " + key_val_str; } return res; } ); return std::shared_ptr<http_response>(new string_response("Received args: {" + recv_args + "}")); } }; int main(int argc, char** argv) { webserver ws = create_webserver(8080); hello_world_resource hwr; ws.register_resource("/hello", &hwr); ws.start(true); return 0; }
Expected behavior:
Received args: {arg1=''}
Received args: {arg1='', arg2=''}
Actual behavior:
Received args: {}
Reproduces how often: 100%
master
I'm submitting a PR with the potential fix.
Prerequisites
Description
For a POST or PUT request with body format
application/x-www-form-urlencoded
, if there are final parameters withkey
, but withoutvalue
these are left unprocessed and not being reported as arguments in the request.Steps to Reproduce
1 . Compile and launch this little code snippet:
Expected behavior:
Received args: {arg1=''}
Received args: {arg1='', arg2=''}
Actual behavior:
Received args: {}
Received args: {arg1=''}
Reproduces how often: 100%
Versions
master
compiled and 0.18.1 compiledAdditional Information
I'm submitting a PR with the potential fix.