Skip to content

Commit

Permalink
Merge branch 'contrib/github_pr_14459' into 'master'
Browse files Browse the repository at this point in the history
fix(http): fix invalid content-length header in http get (GitHub PR)

Closes IDFGH-13571

See merge request espressif/esp-idf!33809
  • Loading branch information
mahavirj committed Sep 26, 2024
2 parents 1c5394d + c87cb85 commit 2913b72
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/esp_http_client/esp_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,12 @@ static esp_err_t esp_http_client_connect(esp_http_client_handle_t client)
static int http_client_prepare_first_line(esp_http_client_handle_t client, int write_len)
{
if (write_len >= 0) {
http_header_set_format(client->request->headers, "Content-Length", "%d", write_len);
const bool length_required = (client->connection_info.method != HTTP_METHOD_GET &&
client->connection_info.method != HTTP_METHOD_HEAD &&
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 {
esp_http_client_set_header(client, "Transfer-Encoding", "chunked");
}
Expand Down

0 comments on commit 2913b72

Please sign in to comment.