From e07b6f39a8c546040399392c565c5c0273f4e191 Mon Sep 17 00:00:00 2001
From: Darrell
Date: Sat, 13 Mar 2021 23:10:54 -0500
Subject: [PATCH] Update HTTPUpdate.cpp
---
libraries/HTTPUpdate/src/HTTPUpdate.cpp | 3 +++
libraries/HTTPUpdate/src/HTTPUpdate.h | 10 ++++++++++
2 files changed, 13 insertions(+)
diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp
index f4c3d250fa7..c7cb8f8db5e 100644
--- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp
+++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp
@@ -35,11 +35,13 @@
HTTPUpdate::HTTPUpdate(void)
: _httpClientTimeout(8000), _ledPin(-1)
{
+ _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
}
HTTPUpdate::HTTPUpdate(int httpClientTimeout)
: _httpClientTimeout(httpClientTimeout), _ledPin(-1)
{
+ _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
}
HTTPUpdate::~HTTPUpdate(void)
@@ -175,6 +177,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
// use HTTP/1.0 for update since the update handler not support any transfer Encoding
http.useHTTP10(true);
http.setTimeout(_httpClientTimeout);
+ http.setFollowRedirects(_followRedirects);
http.setUserAgent("ESP32-http-Update");
http.addHeader("Cache-Control", "no-cache");
http.addHeader("x-ESP32-STA-MAC", WiFi.macAddress());
diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.h b/libraries/HTTPUpdate/src/HTTPUpdate.h
index f126cba0639..7b2d3909851 100644
--- a/libraries/HTTPUpdate/src/HTTPUpdate.h
+++ b/libraries/HTTPUpdate/src/HTTPUpdate.h
@@ -63,6 +63,15 @@ class HTTPUpdate
{
_rebootOnUpdate = reboot;
}
+
+ /**
+ * set redirect follow mode. See `followRedirects_t` enum for avaliable modes.
+ * @param follow
+ */
+ void setFollowRedirects(followRedirects_t follow)
+ {
+ _followRedirects = follow;
+ }
void setLedPin(int ledPin = -1, uint8_t ledOn = HIGH)
{
@@ -89,6 +98,7 @@ class HTTPUpdate
bool _rebootOnUpdate = true;
private:
int _httpClientTimeout;
+ followRedirects_t _followRedirects;
int _ledPin;
uint8_t _ledOn;