Closed LeSpocky closed 2 years ago
I tried solving this. First I added a test case, you already find that in a branch in my personal fork. Then I identified the place in webserver.cpp where the header should be added. Now I'm stuck when constructing the header line itself. It would require looping over the allowed_methods
private member of class httpserver::http_resource
and there's no member function to do that. What would be your preferred way of extending httpserver::http_resource
here?
Would appreciate any input, because that would mean altering the public API, right?
Hi @LeSpocky, thanks for raising the issue and taking it up to fix it. It is much appreciated.
I think that a public method that iterates over the allowed_methods and returns a list of allowed ones will make sense in public interface. Essentially:
std::list<std::string> http_resource::get_allowed_methods();
At the same time, I think it might be worth changing the name of the internal structure from "allowed_methods" to something else (i.e. "method_state") that indicates it doesn't contain only allowed_methods but the state of every method (allowed or not). That would avoid confusion given the name I am proposing for the method above.
Prerequisites
Description
RFC 7231 states in section 6.5.5. 405 Method Not Allowed:
That
Allow:
header is not sent by libhttpserver.Steps to Reproduce
examples/allowing_disallowing_methods
curl -XPOST -v http://localhost:8080/hello
Expected behavior: send that header based on
allowed_methods
member ofclass http_resource
Actual behavior: HTTP header
Allow:
is not sentReproduces how often: always, at least unless webserver is constructed with a custom
method_not_allowed_resource
.Versions
Additional Information
curl output (tail):
Example and explanation for allow header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Allow