Skip to content
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

[BUG] Final keys without values are not processed for POST body #268

Open
1 task done
JavierJF opened this issue May 13, 2022 · 0 comments
Open
1 task done

[BUG] Final keys without values are not processed for POST body #268

JavierJF opened this issue May 13, 2022 · 0 comments
Assignees
Labels
bug Confirmed bugs or reports that are very likely to be bugs.

Comments

@JavierJF
Copy link

JavierJF commented May 13, 2022

Prerequisites

Description

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.

Steps to Reproduce

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;
}
  1. Perform the following requests to the registered endpoint.

Expected behavior:

  • Response for first request should be: Received args: {arg1=''}
  • Response for second request should be: Received args: {arg1='', arg2=''}

Actual behavior:

  • Response for first request is: Received args: {}
  • Response for second request is: Received args: {arg1=''}

Reproduces how often: 100%

Versions

  • OS version: Linux 5.17.5-arch1-2
  • libhttpserver version: master compiled and 0.18.1 compiled
  • libmicrohttpd version: libmicrohttpd-0.9.68 compiled

Additional Information

I'm submitting a PR with the potential fix.

@JavierJF JavierJF added the bug Confirmed bugs or reports that are very likely to be bugs. label May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs.
Projects
None yet
Development

No branches or pull requests

2 participants