ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
http_request_idf.h
Go to the documentation of this file.
1#pragma once
2
3#include "http_request.h"
4
5#ifdef USE_ESP32
6
7#include <esp_event.h>
8#include <esp_http_client.h>
9#include <esp_netif.h>
10#include <esp_tls.h>
11
12namespace esphome::http_request {
13
15 public:
16 HttpContainerIDF(esp_http_client_handle_t client) : client_(client) {}
17 int read(uint8_t *buf, size_t max_len) override;
18 void end() override;
19
21 void feed_wdt();
22
23 void set_response_headers(std::map<std::string, std::list<std::string>> &response_headers) {
24 this->response_headers_ = std::move(response_headers);
25 }
26
27 protected:
28 esp_http_client_handle_t client_;
29};
30
32 public:
33 void dump_config() override;
34
35 void set_buffer_size_rx(uint16_t buffer_size_rx) { this->buffer_size_rx_ = buffer_size_rx; }
36 void set_buffer_size_tx(uint16_t buffer_size_tx) { this->buffer_size_tx_ = buffer_size_tx; }
37
38 protected:
39 std::shared_ptr<HttpContainer> perform(const std::string &url, const std::string &method, const std::string &body,
40 const std::list<Header> &request_headers,
41 const std::set<std::string> &collect_headers) override;
42 // if zero ESP-IDF will use DEFAULT_HTTP_BUF_SIZE
43 uint16_t buffer_size_rx_{};
44 uint16_t buffer_size_tx_{};
45
47 static esp_err_t http_event_handler(esp_http_client_event_t *evt);
48};
49
50} // namespace esphome::http_request
51
52#endif // USE_ESP32
std::map< std::string, std::list< std::string > > response_headers_
int read(uint8_t *buf, size_t max_len) override
HttpContainerIDF(esp_http_client_handle_t client)
void set_response_headers(std::map< std::string, std::list< std::string > > &response_headers)
void feed_wdt()
Feeds the watchdog timer if the executing task has one attached.
void set_buffer_size_tx(uint16_t buffer_size_tx)
void set_buffer_size_rx(uint16_t buffer_size_rx)
static esp_err_t http_event_handler(esp_http_client_event_t *evt)
Monitors the http client events to gather response headers.
std::shared_ptr< HttpContainer > perform(const std::string &url, const std::string &method, const std::string &body, const std::list< Header > &request_headers, const std::set< std::string > &collect_headers) override