mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
http_request: Cleanups and safety improvements (#5360)
This commit is contained in:
parent
61edf8c196
commit
157a3e53dd
1 changed files with 9 additions and 18 deletions
|
@ -80,8 +80,6 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(std::string, url)
|
TEMPLATABLE_VALUE(std::string, url)
|
||||||
TEMPLATABLE_VALUE(const char *, method)
|
TEMPLATABLE_VALUE(const char *, method)
|
||||||
TEMPLATABLE_VALUE(std::string, body)
|
TEMPLATABLE_VALUE(std::string, body)
|
||||||
TEMPLATABLE_VALUE(const char *, useragent)
|
|
||||||
TEMPLATABLE_VALUE(uint16_t, timeout)
|
|
||||||
|
|
||||||
void add_header(const char *key, TemplatableValue<const char *, Ts...> value) { this->headers_.insert({key, value}); }
|
void add_header(const char *key, TemplatableValue<const char *, Ts...> value) { this->headers_.insert({key, value}); }
|
||||||
|
|
||||||
|
@ -105,25 +103,18 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||||
auto f = std::bind(&HttpRequestSendAction<Ts...>::encode_json_func_, this, x..., std::placeholders::_1);
|
auto f = std::bind(&HttpRequestSendAction<Ts...>::encode_json_func_, this, x..., std::placeholders::_1);
|
||||||
this->parent_->set_body(json::build_json(f));
|
this->parent_->set_body(json::build_json(f));
|
||||||
}
|
}
|
||||||
if (this->useragent_.has_value()) {
|
std::list<Header> headers;
|
||||||
this->parent_->set_useragent(this->useragent_.value(x...));
|
for (const auto &item : this->headers_) {
|
||||||
}
|
auto val = item.second;
|
||||||
if (this->timeout_.has_value()) {
|
Header header;
|
||||||
this->parent_->set_timeout(this->timeout_.value(x...));
|
header.name = item.first;
|
||||||
}
|
header.value = val.value(x...);
|
||||||
if (!this->headers_.empty()) {
|
headers.push_back(header);
|
||||||
std::list<Header> headers;
|
|
||||||
for (const auto &item : this->headers_) {
|
|
||||||
auto val = item.second;
|
|
||||||
Header header;
|
|
||||||
header.name = item.first;
|
|
||||||
header.value = val.value(x...);
|
|
||||||
headers.push_back(header);
|
|
||||||
}
|
|
||||||
this->parent_->set_headers(headers);
|
|
||||||
}
|
}
|
||||||
|
this->parent_->set_headers(headers);
|
||||||
this->parent_->send(this->response_triggers_);
|
this->parent_->send(this->response_triggers_);
|
||||||
this->parent_->close();
|
this->parent_->close();
|
||||||
|
this->parent_->set_body("");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue