Skip to content

Commit

Permalink
Update HTTPUpdate.cpp (#4942)
Browse files Browse the repository at this point in the history
This is a mirror of a change in esp8266 needed to update with a url that redirects.
  • Loading branch information
DTTerastar committed Mar 16, 2021
1 parent 5b84527 commit 63c51d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libraries/HTTPUpdate/src/HTTPUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions libraries/HTTPUpdate/src/HTTPUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -89,6 +98,7 @@ class HTTPUpdate
bool _rebootOnUpdate = true;
private:
int _httpClientTimeout;
followRedirects_t _followRedirects;

int _ledPin;
uint8_t _ledOn;
Expand Down

0 comments on commit 63c51d5

Please sign in to comment.