From c87cb854f3205cb3f1c69f31ac654a4f278d5628 Mon Sep 17 00:00:00 2001 From: Serhii Kulyk Date: Wed, 28 Aug 2024 20:32:23 +0200 Subject: [PATCH] fix(http): fix invalid content-length header in http get --- components/esp_http_client/esp_http_client.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 651c7e2d51..fc2fbb4f2e 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -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"); }