1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-01 15:41:52 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Jesse Hills
b5b4047241 Use err from getting chunk length 2024-06-21 15:42:37 +12:00
Keith Burzinski
ddd5e345ac Int stuff 2024-06-20 22:18:37 -05:00
Jesse Hills
c354afda17 [http_request] Get chunked content length and add some logs 2024-06-21 14:33:10 +12:00

View File

@@ -86,6 +86,8 @@ std::shared_ptr<HttpContainer> 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,26 @@ std::shared_ptr<HttpContainer> HttpRequestIDF::start(std::string url, std::strin
return nullptr;
}
ESP_LOGV(TAG, "HTTP Request body written: %d", 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);
if (err != ESP_OK) {
this->status_momentary_error("failed", 1000);
ESP_LOGE(TAG, "Failed to get chunk length: %s", esp_err_to_name(err));
esp_http_client_cleanup(client);
return nullptr;
}
container->content_length = length;
}
const auto status_code = esp_http_client_get_status_code(client);
container->status_code = status_code;
ESP_LOGD(TAG, "Status %d", 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 +165,8 @@ void HttpContainerIDF::end() {
esp_http_client_close(this->client_);
esp_http_client_cleanup(this->client_);
ESP_LOGV(TAG, "HTTP Request ended: %d", this->status_code);
}
} // namespace http_request