ESPHome 2025.5.0
Loading...
Searching...
No Matches
http_request.cpp
Go to the documentation of this file.
1#include "http_request.h"
2
3#include "esphome/core/log.h"
4
5#include <cinttypes>
6
7namespace esphome {
8namespace http_request {
9
10static const char *const TAG = "http_request";
11
13 ESP_LOGCONFIG(TAG, "HTTP Request:");
14 ESP_LOGCONFIG(TAG, " Timeout: %ums", this->timeout_);
15 ESP_LOGCONFIG(TAG, " User-Agent: %s", this->useragent_);
16 ESP_LOGCONFIG(TAG, " Follow redirects: %s", YESNO(this->follow_redirects_));
17 ESP_LOGCONFIG(TAG, " Redirect limit: %d", this->redirect_limit_);
18 if (this->watchdog_timeout_ > 0) {
19 ESP_LOGCONFIG(TAG, " Watchdog Timeout: %" PRIu32 "ms", this->watchdog_timeout_);
20 }
21}
22
23std::string HttpContainer::get_response_header(const std::string &header_name) {
24 auto response_headers = this->get_response_headers();
25 auto header_name_lower_case = str_lower_case(header_name);
26 if (response_headers.count(header_name_lower_case) == 0) {
27 ESP_LOGW(TAG, "No header with name %s found", header_name_lower_case.c_str());
28 return "";
29 } else {
30 auto values = response_headers[header_name_lower_case];
31 if (values.empty()) {
32 ESP_LOGE(TAG, "header with name %s returned an empty list, this shouldn't happen",
33 header_name_lower_case.c_str());
34 return "";
35 } else {
36 auto header_value = values.front();
37 ESP_LOGD(TAG, "Header with name %s found with value %s", header_name_lower_case.c_str(), header_value.c_str());
38 return header_value;
39 }
40 }
41}
42
43} // namespace http_request
44} // namespace esphome
std::string get_response_header(const std::string &header_name)
std::map< std::string, std::list< std::string > > get_response_headers()
Get response headers.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string str_lower_case(const std::string &str)
Convert the string to lower case.
Definition helpers.cpp:290