ESPHome 2026.3.0-dev
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
8
9static const char *const TAG = "http_request";
10
12 ESP_LOGCONFIG(TAG,
13 "HTTP Request:\n"
14 " Timeout: %ums\n"
15 " User-Agent: %s\n"
16 " Follow redirects: %s\n"
17 " Redirect limit: %d",
18 this->timeout_, this->useragent_, YESNO(this->follow_redirects_), this->redirect_limit_);
19 if (this->watchdog_timeout_ > 0) {
20 ESP_LOGCONFIG(TAG, " Watchdog Timeout: %" PRIu32 "ms", this->watchdog_timeout_);
21 }
22}
23
24std::string HttpContainer::get_response_header(const std::string &header_name) {
25 auto lower = str_lower_case(header_name);
26 for (const auto &entry : this->response_headers_) {
27 if (entry.name == lower) {
28 ESP_LOGD(TAG, "Header with name %s found with value %s", lower.c_str(), entry.value.c_str());
29 return entry.value;
30 }
31 }
32 ESP_LOGW(TAG, "No header with name %s found", lower.c_str());
33 return "";
34}
35
36} // namespace esphome::http_request
std::string get_response_header(const std::string &header_name)
std::vector< Header > response_headers_
std::string str_lower_case(const std::string &str)
Convert the string to lower case.
Definition helpers.cpp:201