-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Closed
Copy link
Description
I created a POST endpoint using the following code:
#include <httplib.h>
using namespace httplib;
int main(void) {
Server svr;
svr.Post("/test", [](const Request &req, Response &res) {
res.set_content("", "text/plain");
});
svr.listen("0.0.0.0", 7777);
}Then I accessed it using curl:
# curl -X POST "http://localhost:7777/test" -v
* Host localhost:7777 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:7777...
* connect to ::1 port 7777 from ::1 port 59000 failed: Connection refused
* Trying 127.0.0.1:7777...
* Connected to localhost (127.0.0.1) port 7777
> POST /test HTTP/1.1
> Host: localhost:7777
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 400 Bad Request
< Connection: close
< Content-Length: 0
<
* Closing connectionAfter analyzing the code, I found that the issue occurs at this location:
Lines 7934 to 7941 in 27ee115
| if (req.method == "DELETE" && !req.has_header("Content-Length")) { | |
| return true; | |
| } | |
| if (!detail::read_content(strm, req, payload_max_length_, res.status, nullptr, | |
| out, true)) { | |
| return false; | |
| } |
Based on my reading of RFC 7231, POST requests don't seem to require a message body, but I could be wrong about this. Should POST requests without Content-Length or Transfer-Encoding headers be accepted?
Metadata
Metadata
Assignees
Labels
No labels