libhttpserver icon indicating copy to clipboard operation
libhttpserver copied to clipboard

Provide a httpserver::http_request factory for testing.

Open bcsgh opened this issue 5 years ago • 1 comments

Is your feature request related to a problem? Please describe. I'm trying to set up self contained unit tests for a httpserver::http_resource implementation but there doesn't seem to be any way to construct the arguments needed to invoke it without resorting to standing up a whole HTTP server which could be impractical or impossible depending on the environment that the test needs to run in (i.e. a restricted uses with no network or file system access) and even where possible forces otherwise unneeded dependencies on things like an HTTP client library.

Describe the solution you'd like I'd like to be able to write something like:

std::unique_ptr<httpserver::http_request> req = httpserver::http_request_factory(HTTP_RESPONCE_TEXT);
auto resp = my_resource.render(*req);
// ... Test resp.

For more advanced usage (https, WebSockets, etc.) the sort of fluent interface that is used to create a httpserver::webserver could be employed.

Describe alternatives you've considered Looking at the test of httpserver it self, it looks like it takes the "use a http client library" approach, but then again, it's testing the server so it has to do that.

bcsgh avatar Dec 01 '20 04:12 bcsgh

This would also likely require some utilities for inspecting the resulting http_response objects.

bcsgh avatar Dec 01 '20 04:12 bcsgh