From c354afda179176bce421bd9c15e11a5bf599a652 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:33:10 +1200 Subject: [PATCH] [http_request] Get chunked content length and add some logs --- .../components/http_request/http_request_idf.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/esphome/components/http_request/http_request_idf.cpp b/esphome/components/http_request/http_request_idf.cpp index 138e0438f4..dfebf06ab4 100644 --- a/esphome/components/http_request/http_request_idf.cpp +++ b/esphome/components/http_request/http_request_idf.cpp @@ -86,6 +86,8 @@ std::shared_ptr HttpRequestIDF::start(std::string url, std::strin return nullptr; } + ESP_LOGV(TAG, "HTTP Request started: %s", url.c_str()); + if (body_len > 0) { int write_left = body_len; int write_index = 0; @@ -108,10 +110,20 @@ std::shared_ptr HttpRequestIDF::start(std::string url, std::strin return nullptr; } + ESP_LOGV(TAG, "HTTP Request body written: %" PRId32, body_len); + container->content_length = esp_http_client_fetch_headers(client); + if (esp_http_client_is_chunked_response(client)) { + ESP_LOGV(TAG, "HTTP Response is chunked"); + int length = 0; + err = esp_http_client_get_chunk_length(client, &length); + container->content_length = length; + } const auto status_code = esp_http_client_get_status_code(client); container->status_code = status_code; + ESP_LOGD(TAG, "Status %" PRId32, status_code); + if (status_code < 200 || status_code >= 300) { ESP_LOGE(TAG, "HTTP Request failed; URL: %s; Code: %d", url.c_str(), status_code); this->status_momentary_error("failed", 1000); @@ -147,6 +159,8 @@ void HttpContainerIDF::end() { esp_http_client_close(this->client_); esp_http_client_cleanup(this->client_); + + ESP_LOGV(TAG, "HTTP Request ended: %" PRId32, this->status_code); } } // namespace http_request