mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +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:
@ -173,7 +173,9 @@ public:
|
||||
void setAuthorization(const char * user, const char * password);
|
||||
void setAuthorization(const char * auth);
|
||||
void setTimeout(uint16_t timeout);
|
||||
|
||||
void setFollowRedirects(bool follow);
|
||||
void setRedirectLimit(uint16_t limit); // max redirects to follow for a single request
|
||||
bool setURL(String url); // handy for handling redirects
|
||||
void useHTTP10(bool usehttp10 = true);
|
||||
|
||||
/// request handling
|
||||
@ -200,12 +202,12 @@ public:
|
||||
|
||||
|
||||
int getSize(void);
|
||||
const String& getLocation(void); // Location header from redirect if 3XX
|
||||
|
||||
WiFiClient& getStream(void);
|
||||
WiFiClient* getStreamPtr(void);
|
||||
int writeToStream(Stream* stream);
|
||||
const String& getString(void);
|
||||
|
||||
static String errorToString(int error);
|
||||
|
||||
protected:
|
||||
@ -215,7 +217,7 @@ protected:
|
||||
};
|
||||
|
||||
bool beginInternal(String url, const char* expectedProtocol);
|
||||
void disconnect();
|
||||
void disconnect(bool preserveClient = false);
|
||||
void clear();
|
||||
int returnError(int error);
|
||||
bool connect(void);
|
||||
@ -250,6 +252,10 @@ protected:
|
||||
int _returnCode = 0;
|
||||
int _size = -1;
|
||||
bool _canReuse = false;
|
||||
bool _followRedirects = false;
|
||||
uint16_t _redirectCount = 0;
|
||||
uint16_t _redirectLimit = 10;
|
||||
String _location;
|
||||
transferEncoding_t _transferEncoding = HTTPC_TE_IDENTITY;
|
||||
std::unique_ptr<StreamString> _payload;
|
||||
};
|
||||
|
Reference in New Issue
Block a user