Skip to content

Commit

Permalink
fix(esp_http_client): Fix invalid content length header
Browse files Browse the repository at this point in the history
In case a request with no content is sent after one with the content
length header set the header of the previous request is sent with the
subsequent one.
For instance, an empty GET request followed by a PUT request will still
indicate the non-zero content length of the previous request.

This is fixed by clearing the content length header when it shouldn't be
set.
  • Loading branch information
chris-durand committed Jan 27, 2025
1 parent c586527 commit 912304b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/esp_http_client/esp_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,8 @@ static int http_client_prepare_first_line(esp_http_client_handle_t client, int w
client->connection_info.method != HTTP_METHOD_DELETE);
if (write_len != 0 || length_required) {
http_header_set_format(client->request->headers, "Content-Length", "%d", write_len);
} else {
http_header_delete(client->request->headers, "Content-Length");
}
} else {
esp_http_client_set_header(client, "Transfer-Encoding", "chunked");
Expand Down

0 comments on commit 912304b

Please sign in to comment.