Add trigger for http actions to receive the status code (#1599)

This commit is contained in:
Jesse Hills authored and GitHub committed 2021-03-22 16:26:10 +13:00
1 parent 8f1eb77e05
commit af3273d930
4 files changed
+35 -3

No files matched your search

@@ -24,7 +24,7 @@ void HttpRequestComponent::set_url(std::string url) {
this->client_.setReuse(true);
}
void HttpRequestComponent::send() {
void HttpRequestComponent::send(const std::vector<HttpRequestResponseTrigger *> &response_triggers) {
bool begin_status = false;
const String url = this->url_.c_str();
#ifdef ARDUINO_ARCH_ESP32
@@ -54,6 +54,9 @@ void HttpRequestComponent::send() {
}
int http_code = this->client_.sendRequest(this->method_, this->body_.c_str());
for (auto *trigger : response_triggers)
trigger->process(http_code);
if (http_code < 0) {
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s", this->url_.c_str(),
HTTPClient::errorToString(http_code).c_str());