Log a clearer diagnostic on HTTP GET with chunked transfer

This commit is contained in:
Andrew Bettison 2017-09-11 15:16:54 +09:30
parent 58573a4345
commit 261fc43849

View File

@ -1315,15 +1315,19 @@ static int http_request_start_body(struct http_request *r)
assert(r->version_major != 0); assert(r->version_major != 0);
assert(r->parsed <= r->end); assert(r->parsed <= r->end);
// No header should probably be treated the same as no content // The absence of a Content-Length: header should probably be treated the same as no content,
// Though some server implementations disagree // although some server implementations disagree:
// http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0275.html // http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0275.html
if (r->request_header.content_length == CONTENT_LENGTH_UNKNOWN && !r->request_header.chunked) if (r->request_header.content_length == CONTENT_LENGTH_UNKNOWN && !r->request_header.chunked)
r->request_header.content_length = 0; r->request_header.content_length = 0;
if (r->verb == HTTP_VERB_GET) { if (r->verb == HTTP_VERB_GET) {
// TODO: Implement HEAD requests (only send response header, not body) // TODO: Implement HEAD requests (only send response header, not body)
if (r->request_header.chunked || r->request_header.content_length != 0) { if (r->request_header.chunked) {
IDEBUGF(r->debug, "Malformed HTTP %s request: chunked Transfer-Encoding not allowed", r->verb);
return 400;
}
if (r->request_header.content_length != 0) {
IDEBUGF(r->debug, "Malformed HTTP %s request: non-zero Content-Length not allowed", r->verb); IDEBUGF(r->debug, "Malformed HTTP %s request: non-zero Content-Length not allowed", r->verb);
return 400; return 400;
} }