|
@@ -10,7 +10,7 @@ using std::make_shared;
|
|
|
using std::string;
|
|
|
using std::shared_ptr;
|
|
|
|
|
|
-http::Client::Client(bool async) : buffer(), async(async) {
|
|
|
+http::Client::Client(int timeoutMs, bool async) : timeoutMs(timeoutMs), async(async), buffer() {
|
|
|
ESP_LOGD(TAG, "Client()");
|
|
|
init();
|
|
|
}
|
|
@@ -24,11 +24,11 @@ void http::Client::init() {
|
|
|
config.path = "/";
|
|
|
config.disable_auto_redirect = false; // do not set to true, IDF bug :(
|
|
|
config.max_redirection_count = 0;
|
|
|
+ config.timeout_ms = timeoutMs;
|
|
|
config.is_async = async;
|
|
|
handle = esp_http_client_init(&config);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
http::Client::~Client() {
|
|
|
ESP_LOGD(TAG, "~Client()");
|
|
|
CHECK(esp_http_client_cleanup(handle));
|
|
@@ -78,14 +78,16 @@ http::Client::performRequest(const kbf::http::Method method, const std::string &
|
|
|
ESP_LOGD(TAG, "success");
|
|
|
return response;
|
|
|
} else if (err == ESP_ERR_HTTP_FETCH_HEADER && !retry) {
|
|
|
- ESP_LOGD(TAG, "fetching headers failed, maybe the connection was dropped? retrying...");
|
|
|
+ // TODO this will happen on timeout as well; perhaps set a retry limit in ctor / get / post?
|
|
|
+ ESP_LOGW(TAG, "fetching headers failed, maybe the connection was dropped? retrying...");
|
|
|
retry = true;
|
|
|
esp_http_client_cleanup(handle);
|
|
|
init();
|
|
|
return get(url);
|
|
|
} else {
|
|
|
ESP_LOGE(TAG, "HTTP GET failed: %s", esp_err_to_name(err));
|
|
|
- ABORT("debug me");
|
|
|
+ if (onError) onError(*this);
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -124,7 +126,6 @@ esp_err_t http::Client::handleHttpEvent(esp_http_client_event_t *event) {
|
|
|
case HTTP_EVENT_DISCONNECTED:
|
|
|
ESP_LOGW(TAG, "disconnected");
|
|
|
client->running = false;
|
|
|
- client->retry = false;
|
|
|
break;
|
|
|
}
|
|
|
|