mirror of
https://github.com/esphome/esphome.git
synced 2025-01-18 20:10:55 +00:00
[http_request] Get chunked content length and add some logs
This commit is contained in:
parent
8045b889d3
commit
c354afda17
@ -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,20 @@ std::shared_ptr<HttpContainer> 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user