16 " Timeout: %" PRIu32
"ms\n"
18 " Follow redirects: %s\n"
19 " Redirect limit: %d\n"
20 " Max concurrent requests: %u",
31 if (entry.name == lower) {
32 ESP_LOGV(TAG,
"Header with name %s found with value %s", lower.c_str(), entry.value.c_str());
40 if (this->
buf !=
nullptr)
63 if (request->finished || request->cancelled)
66 request->cancelled =
true;
72 ESP_LOGW(TAG,
"Shutting down; %u requests dropped", dropped);
90 for (; *link !=
nullptr; link = &(*link)->
next) {
103 ESP_LOGW(TAG,
"Too many requests waiting; request dropped");
113 if (this->
busy_ != 0)
124 if (request->owner == owner)
125 request->cancelled =
true;
127 if (this->
busy_ == 0)
136 if (request->finished || request->cancelled)
139 if (request->container ==
nullptr)
141 if (!request->cancelled && (request->failed || this->advance_(request)))
145 if (this->
busy_ == 0)
152 if (this->
busy_ != 0)
170 auto progress = request->
container->poll();
180 if (request->
buf ==
nullptr) {
182 ESP_LOGW(TAG,
"Could not allocate %zu bytes for the response body", request->
buf_size);
197 if (read_or_error < 0) {
198 ESP_LOGW(TAG,
"Response body read failed after %zu bytes", request->
read_index);
201 if (read_or_error == 0) {
202 if (request->
container->is_read_complete())
206 ESP_LOGW(TAG,
"Response body timed out after %zu bytes", request->
read_index);
215 if (!request->
container->is_read_complete()) {
216 ESP_LOGW(TAG,
"Response body is larger than max_response_buffer_size; kept the first %zu bytes", request->
buf_size);
232 if (!request->finished && !request->cancelled) {
233 link = &request->
next;
236 *link = request->
next;
237 if (request->container !=
nullptr)
239 request->free_buffer();
void feed_wdt()
Feed the task watchdog.
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
An STL allocator that uses SPI or internal RAM.
void deallocate(T *p, size_t n)
std::string get_response_header(const std::string &header_name)
Get the value of a response header by name.
std::vector< Header > response_headers_
bool advance_(PendingRequest *request)
void cancel(void *owner)
For HttpRequestSendAction: drop the requests of a stopped action without firing their triggers.
static constexpr uint32_t READ_BUDGET_MS
Longest time one loop() pass spends reading a response body.
void on_shutdown() override
void finish_(PendingRequest *request)
void on_safe_shutdown() override
uint32_t watchdog_timeout_
PendingRequest * requests_
void begin_request_(PendingRequest *request)
void submit(PendingRequest *request)
For HttpRequestSendAction: queue a request and take ownership of it.
std::shared_ptr< HttpContainer > start(const char *url, const char *method, const std::string &body, const std::vector< Header > &request_headers)
static constexpr uint8_t MAX_QUEUED
Requests that wait for a free slot; more are dropped with on_error.
void dump_config() override
@ HTTP_REQUEST_PROGRESS_FAILED
No response; the container must still be ended.
@ HTTP_REQUEST_PROGRESS_PENDING
Still connecting, sending, or waiting for the response headers.
@ REQUEST_EVENT_FINISH
Fire the triggers and continue the action chain.
@ REQUEST_EVENT_START
Build the request and call begin()
@ REQUEST_EVENT_DESTROY
Free the request.
@ REQUEST_EVENT_ABANDON
Dropped at shutdown: stop the action, so that it can run again.
ESPHOME_LOG_TAG(TAG, "http_request")
std::string str_lower_case(const std::string &str)
Convert the string to lower case.
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
A request from an HttpRequestSendAction, run from HttpRequestComponent::loop().
std::shared_ptr< HttpContainer > container