Open
Description
Prerequisites
- Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo%3Aetr%2Flibhttpserver&type=Issues
Description
The result from calling http_request::get_args()
will not contain URL query parameters if the resource URL has path parameters. This is due to webserver::finalize_answer(...)
calling http_server::set_arg(...)
for each URL path argument, thus rendering http_request::cache::unescaped_args
non-empty. http_request::get_args()
will call http_request::populate_args()
, which will do nothing if unescaped_args
is non-empty.
Steps to Reproduce
- Change line
examples/hello_with_get_arg.cpp:26
from
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Hello: " + std::string(req.get_arg("name"))));
to
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(std::string(req.get_arg("greeting")) + ", " + std::string(req.get_arg("name"))));
- Change line
examples/hello_with_get_arg.cpp:34
from
ws.register_resource("/hello", &hwr);
to lines
hwr.disallow_all();
hwr.set_allowing("GET", true);
ws.register_resource("/{greeting}", &hwr);
- Build and start example server
hello_with_get_arg
in a terminal. - In a second terminal, run
curl http://localhost:8080/Howdy?name=Bob
Expected behavior: Server responds with text "Howdy, Bob"
Actual behavior: Server responds with "Howdy, "
Reproduces how often: 100%
Versions
- OS version
Linux gd 6.8.0-50-generic #51~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 21 12:03:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
- libhttpserver version 0.19.0, compiled
- libmicrohttpd version 1.0.1, compiled
Additional Information
Full example program, modified as specified in steps to reproduce.
#include <httpserver.hpp>
class hello_world_resource : public httpserver::http_resource {
public:
std::shared_ptr<httpserver::http_response> render(const httpserver::http_request& req) {
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response(std::string(req.get_arg("greeting")) + ", " + std::string(req.get_arg("name"))));
}
};
int main() {
httpserver::webserver ws = httpserver::create_webserver(8080);
hello_world_resource hwr;
hwr.disallow_all();
hwr.set_allowing("GET", true);
ws.register_resource("/{greeting}", &hwr);
ws.start(true);
return 0;
}