mirror of
https://github.com/esphome/esphome.git
synced 2026-02-25 04:45:29 -07:00
[http_request] Replace std::map with std::vector in action template (#14026)
This commit is contained in:
@@ -302,10 +302,14 @@ async def http_request_action_to_code(config, action_id, template_arg, args):
|
||||
lambda_ = await cg.process_lambda(json_, args_, return_type=cg.void)
|
||||
cg.add(var.set_json(lambda_))
|
||||
else:
|
||||
cg.add(var.init_json(len(json_)))
|
||||
for key in json_:
|
||||
template_ = await cg.templatable(json_[key], args, cg.std_string)
|
||||
cg.add(var.add_json(key, template_))
|
||||
for key, value in config.get(CONF_REQUEST_HEADERS, {}).items():
|
||||
request_headers = config.get(CONF_REQUEST_HEADERS, {})
|
||||
if request_headers:
|
||||
cg.add(var.init_request_headers(len(request_headers)))
|
||||
for key, value in request_headers.items():
|
||||
template_ = await cg.templatable(value, args, cg.const_char_ptr)
|
||||
cg.add(var.add_request_header(key, template_))
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
@@ -399,13 +398,15 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||
TEMPLATABLE_VALUE(bool, capture_response)
|
||||
#endif
|
||||
|
||||
void init_request_headers(size_t count) { this->request_headers_.init(count); }
|
||||
void add_request_header(const char *key, TemplatableValue<const char *, Ts...> value) {
|
||||
this->request_headers_.insert({key, value});
|
||||
this->request_headers_.push_back({key, value});
|
||||
}
|
||||
|
||||
void add_collect_header(const char *value) { this->lower_case_collect_headers_.push_back(value); }
|
||||
|
||||
void add_json(const char *key, TemplatableValue<std::string, Ts...> value) { this->json_.insert({key, value}); }
|
||||
void init_json(size_t count) { this->json_.init(count); }
|
||||
void add_json(const char *key, TemplatableValue<std::string, Ts...> value) { this->json_.push_back({key, value}); }
|
||||
|
||||
void set_json(std::function<void(Ts..., JsonObject)> json_func) { this->json_func_ = json_func; }
|
||||
|
||||
@@ -507,9 +508,9 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||
}
|
||||
void encode_json_func_(Ts... x, JsonObject root) { this->json_func_(x..., root); }
|
||||
HttpRequestComponent *parent_;
|
||||
std::map<const char *, TemplatableValue<const char *, Ts...>> request_headers_{};
|
||||
FixedVector<std::pair<const char *, TemplatableValue<const char *, Ts...>>> request_headers_{};
|
||||
std::vector<std::string> lower_case_collect_headers_{"content-type", "content-length"};
|
||||
std::map<const char *, TemplatableValue<std::string, Ts...>> json_{};
|
||||
FixedVector<std::pair<const char *, TemplatableValue<std::string, Ts...>>> json_{};
|
||||
std::function<void(Ts..., JsonObject)> json_func_{nullptr};
|
||||
#ifdef USE_HTTP_REQUEST_RESPONSE
|
||||
Trigger<std::shared_ptr<HttpContainer>, std::string &, Ts...> success_trigger_with_response_;
|
||||
|
||||
Reference in New Issue
Block a user