Fix issuing 411 responses as a client

15.5.12. 411 Length Required

The 411 (Length Required) status code indicates that the server refuses to accept the request without a defined Content-Length (Section 8.6). The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the request content.

fixes #2969
This commit is contained in:
Sergio R. Caprile 2024-11-21 18:17:59 -03:00
parent 2df53c3d27
commit 5c305e7fa8
2 changed files with 4 additions and 4 deletions

View File

@ -2417,8 +2417,8 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
require_content_len = status >= 200 && status != 204 && status != 304;
}
if (require_content_len) {
mg_http_reply(c, 411, "", "");
MG_ERROR(("%s", "Content length missing from request"));
if (!c->is_client) mg_http_reply(c, 411, "", "");
MG_ERROR(("Content length missing from %s", is_response ? "response" : "request"));
}
}

View File

@ -1059,8 +1059,8 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
require_content_len = status >= 200 && status != 204 && status != 304;
}
if (require_content_len) {
mg_http_reply(c, 411, "", "");
MG_ERROR(("%s", "Content length missing from request"));
if (!c->is_client) mg_http_reply(c, 411, "", "");
MG_ERROR(("Content length missing from %s", is_response ? "response" : "request"));
}
}