Skip to content

Commit

Permalink
Fix transfer-encoding vs. content-length.
Browse files Browse the repository at this point in the history
transfer-encoding = chunked vs. content-length encoding is documented
in rfc 2616 3.6.1 and rfc 7230 4.1.  In both cases, it is
documented that if transfer-encoding == 'chunked', then content-length
should not be supplied by a client, and must not be processed by a server.

The previous code in civetweb allowed content-length to override
transfer-encoding=chunked, which is clearly wrong by the standard.
This chnage corrects the order of those checks.

Signed-off-by: Marcus Watts <[email protected]>
  • Loading branch information
mdw-at-linuxbox committed Jul 28, 2020
1 parent cb9d876 commit 54426bf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/civetweb.c
Original file line number Diff line number Diff line change
Expand Up @@ -15396,6 +15396,12 @@ get_request(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)

/* Message is a valid request */
if ((cl = get_header(conn->request_info.http_headers,
conn->request_info.num_headers,
"Transfer-Encoding")) != NULL
&& !mg_strcasecmp(cl, "chunked")) {
conn->is_chunked = 1;
conn->content_len = -1; /* unknown content length */
} else if ((cl = get_header(conn->request_info.http_headers,
conn->request_info.num_headers,
"Content-Length")) != NULL) {
/* Request/response has content length set */
Expand All @@ -15413,12 +15419,6 @@ get_request(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)
}
/* Publish the content length back to the request info. */
conn->request_info.content_length = conn->content_len;
} else if ((cl = get_header(conn->request_info.http_headers,
conn->request_info.num_headers,
"Transfer-Encoding")) != NULL
&& !mg_strcasecmp(cl, "chunked")) {
conn->is_chunked = 1;
conn->content_len = -1; /* unknown content length */
} else if (get_http_method_info(conn->request_info.request_method)
->request_has_body) {
/* POST or PUT request without content length set */
Expand Down

0 comments on commit 54426bf

Please sign in to comment.