mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
optionally allow redirects on HTTPClient & OTA updates (#5009)
* optionally allow redirects on http OTA updates * Refactored HTTPClient::begin(url...) & setURL functions, now only beginInternal parses URL, sets ports Added HTTPRedirect example. * fix indentation for style check * add space after while for style check * don't use deprecated begin method in redirect example * moved redirect handling code to HTTPClient. only GET and HEAD requests are currently handled automatically Redirects that fail to be automatically handled return the redirect code as before * added support for POST/303 redirect added device redirect tests * add missing getLocation() implementation * if the new location is only a path then only update the URI
This commit is contained in:
@ -30,12 +30,12 @@ extern "C" uint32_t _SPIFFS_start;
|
||||
extern "C" uint32_t _SPIFFS_end;
|
||||
|
||||
ESP8266HTTPUpdate::ESP8266HTTPUpdate(void)
|
||||
: _httpClientTimeout(8000), _ledPin(-1)
|
||||
: _httpClientTimeout(8000), _followRedirects(false), _ledPin(-1)
|
||||
{
|
||||
}
|
||||
|
||||
ESP8266HTTPUpdate::ESP8266HTTPUpdate(int httpClientTimeout)
|
||||
: _httpClientTimeout(httpClientTimeout), _ledPin(-1)
|
||||
: _httpClientTimeout(httpClientTimeout), _followRedirects(false), _ledPin(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -261,6 +261,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
|
||||
// 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(F("ESP8266-http-Update"));
|
||||
http.addHeader(F("x-ESP8266-STA-MAC"), WiFi.macAddress());
|
||||
http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress());
|
||||
|
@ -74,6 +74,11 @@ public:
|
||||
_rebootOnUpdate = reboot;
|
||||
}
|
||||
|
||||
void followRedirects(bool follow)
|
||||
{
|
||||
_followRedirects = follow;
|
||||
}
|
||||
|
||||
void setLedPin(int ledPin = -1, uint8_t ledOn = HIGH)
|
||||
{
|
||||
_ledPin = ledPin;
|
||||
@ -129,6 +134,7 @@ protected:
|
||||
bool _rebootOnUpdate = true;
|
||||
private:
|
||||
int _httpClientTimeout;
|
||||
bool _followRedirects;
|
||||
|
||||
int _ledPin;
|
||||
uint8_t _ledOn;
|
||||
|
Reference in New Issue
Block a user