mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[http_request] Fix usage of http response body (#17713)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
co-authored by
J. Nick Koston
parent
5a86e26f68
commit
7738464f0b
@@ -488,10 +488,10 @@ template<typename... Ts> class HttpRequestSendAction final : public Action<Ts...
|
||||
body = this->body_.value(x...);
|
||||
}
|
||||
if (!this->json_.empty()) {
|
||||
body = json::build_json([this, x...](JsonObject root) { this->encode_json_(x..., root); });
|
||||
body = json::build_json([this, x...](JsonObject root) mutable { this->encode_json_(x..., root); });
|
||||
}
|
||||
if (this->json_func_ != nullptr) {
|
||||
body = json::build_json([this, x...](JsonObject root) { this->json_func_(x..., root); });
|
||||
body = json::build_json([this, x...](JsonObject root) mutable { this->json_func_(x..., root); });
|
||||
}
|
||||
std::vector<Header> request_headers;
|
||||
request_headers.reserve(this->request_headers_.size());
|
||||
|
||||
@@ -59,6 +59,24 @@ esphome:
|
||||
id: test_regression_light
|
||||
brightness: 100%
|
||||
effect: "None"
|
||||
- http_request.get:
|
||||
url: https://esphome.io
|
||||
capture_response: true
|
||||
on_response:
|
||||
then:
|
||||
# Regression test: http_request.post with json: (dict variant) inside
|
||||
# on_response of a capture_response: true request puts std::string&
|
||||
# (body) into the nested action's Ts..., which exposes a
|
||||
# const-correctness bug in HttpRequestSendAction::play() where
|
||||
# encode_json_ receives const copies of non-const reference args.
|
||||
- http_request.post:
|
||||
url: https://esphome.io
|
||||
json:
|
||||
status: "ok"
|
||||
# Same with json: lambda variant, exercises json_func_ path
|
||||
- http_request.post:
|
||||
url: https://esphome.io
|
||||
json: !lambda "root[\"status\"] = \"ok\";"
|
||||
|
||||
http_request:
|
||||
useragent: esphome/tagreader
|
||||
|
||||
Reference in New Issue
Block a user