From 2b21c0a2b20f6fb3b8afdd88d05cfafefa7f5b19 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Feb 2026 18:59:20 -0600 Subject: [PATCH 1/2] [http_request] Rename response_headers param to collect_headers in host Align with IDF and Arduino implementations where the parameter is named collect_headers. --- esphome/components/http_request/http_request_host.cpp | 4 ++-- esphome/components/http_request/http_request_host.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/http_request/http_request_host.cpp b/esphome/components/http_request/http_request_host.cpp index 36aa463bfa..c804997d83 100644 --- a/esphome/components/http_request/http_request_host.cpp +++ b/esphome/components/http_request/http_request_host.cpp @@ -19,7 +19,7 @@ static const char *const TAG = "http_request.host"; std::shared_ptr HttpRequestHost::perform(const std::string &url, const std::string &method, const std::string &body, const std::list
&request_headers, - const std::vector &response_headers) { + const std::vector &collect_headers) { if (!network::is_connected()) { this->status_momentary_error("failed", 1000); ESP_LOGW(TAG, "HTTP Request failed; Not connected to network"); @@ -116,7 +116,7 @@ std::shared_ptr HttpRequestHost::perform(const std::string &url, for (auto header : response.headers) { ESP_LOGD(TAG, "Header: %s: %s", header.first.c_str(), header.second.c_str()); auto lower_name = str_lower_case(header.first); - if (should_collect_header(response_headers, lower_name)) { + if (should_collect_header(collect_headers, lower_name)) { container->response_headers_.push_back({lower_name, header.second}); } } diff --git a/esphome/components/http_request/http_request_host.h b/esphome/components/http_request/http_request_host.h index b63da4daa7..01b52fb7af 100644 --- a/esphome/components/http_request/http_request_host.h +++ b/esphome/components/http_request/http_request_host.h @@ -20,7 +20,7 @@ class HttpRequestHost : public HttpRequestComponent { public: std::shared_ptr perform(const std::string &url, const std::string &method, const std::string &body, const std::list
&request_headers, - const std::vector &response_headers) override; + const std::vector &collect_headers) override; void set_ca_path(const char *ca_path) { this->ca_path_ = ca_path; } protected: From 87e998f455bf6cf88fad0257bf42ab8d2124daba Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Feb 2026 19:05:44 -0600 Subject: [PATCH 2/2] [http_request] Replace std::map with std::vector in action template request_headers_ and json_ are populated at config time via add_request_header()/add_json() and only iterated linearly at runtime. std::map's red-black tree is unnecessary overhead for these small collections. Drop the include. --- esphome/components/http_request/http_request.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/esphome/components/http_request/http_request.h b/esphome/components/http_request/http_request.h index cbf6273b51..17aeeba7d0 100644 --- a/esphome/components/http_request/http_request.h +++ b/esphome/components/http_request/http_request.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -401,12 +400,12 @@ template class HttpRequestSendAction : public Action { #endif void add_request_header(const char *key, TemplatableValue value) { - this->request_headers_.insert({key, value}); + this->request_headers_.push_back({key, value}); } void add_collect_header(const char *value) { this->collect_headers_.push_back(value); } - void add_json(const char *key, TemplatableValue value) { this->json_.insert({key, value}); } + void add_json(const char *key, TemplatableValue value) { this->json_.push_back({key, value}); } void set_json(std::function json_func) { this->json_func_ = json_func; } @@ -508,9 +507,9 @@ template class HttpRequestSendAction : public Action { } void encode_json_func_(Ts... x, JsonObject root) { this->json_func_(x..., root); } HttpRequestComponent *parent_; - std::map> request_headers_{}; + std::vector>> request_headers_{}; std::vector collect_headers_{"content-type", "content-length"}; - std::map> json_{}; + std::vector>> json_{}; std::function json_func_{nullptr}; #ifdef USE_HTTP_REQUEST_RESPONSE Trigger, std::string &, Ts...> success_trigger_with_response_;