Skip to content

Commit 3c4945b

Browse files
committed
Added 'setFollowRedirects' function
1 parent 6f8a0fa commit 3c4945b

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/Inkplate.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ class Inkplate : public System, public Graphics
9999
bool joinAP(const char *ssid, const char *pass)
100100
{
101101
return NetworkClient::joinAP(ssid, pass);
102-
}
102+
};
103+
void setFollowRedirects(followRedirects_t follow)
104+
{
105+
NetworkClient::setFollowRedirects(follow);
106+
};
103107
void disconnect()
104108
{
105109
NetworkClient::disconnect();

src/include/NetworkClient.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,16 @@ uint8_t *NetworkClient::downloadFileHTTPS(const char *url, int32_t *defaultLen)
193193
bool sleep = WiFi.getSleep();
194194
WiFi.setSleep(false);
195195

196-
// Create a new HTTP client and connect using HTTPS
196+
// Create a new HTTP client
197197
HTTPClient http;
198198
http.getStream().setNoDelay(true);
199199
http.getStream().setTimeout(1000);
200+
201+
// Set the 'follow redirects' option
202+
// Default is HTTPC_DISABLE_FOLLOW_REDIRECTS
203+
http.setFollowRedirects(followRedirects);
204+
205+
// Connect with HTTPS
200206
http.begin(*client, host, 443, pathToResource, true);
201207

202208
// Make GET request
@@ -305,6 +311,12 @@ uint8_t *NetworkClient::downloadFile(const char *url, int32_t *defaultLen)
305311
HTTPClient http;
306312
http.getStream().setNoDelay(true);
307313
http.getStream().setTimeout(1);
314+
315+
// Set the 'follow redirects' option
316+
// Default is HTTPC_DISABLE_FOLLOW_REDIRECTS
317+
http.setFollowRedirects(followRedirects);
318+
319+
// Connect with HTTP
308320
http.begin(url);
309321

310322
int httpCode = http.GET();
@@ -349,4 +361,21 @@ uint8_t *NetworkClient::downloadFile(const char *url, int32_t *defaultLen)
349361
WiFi.setSleep(sleep);
350362

351363
return buffer;
352-
}
364+
}
365+
366+
/**
367+
* @brief Set if Inkplate should follow redirects when making HTTP requests
368+
*
369+
* @param followRedirects_t f, the various settings are:
370+
* -'HTTPC_DISABLE_FOLLOW_REDIRECTS' - no redirection will be followed (default)
371+
* -'HTTPC_STRICT_FOLLOW_REDIRECTS' - strict RFC2616, only requests using
372+
* GET or HEAD methods will be redirected
373+
* -'HTTPC_FORCE_FOLLOW_REDIRECTS' - all redirections will be followed
374+
*
375+
* @returns None
376+
*
377+
*/
378+
void NetworkClient::setFollowRedirects(followRedirects_t f)
379+
{
380+
this->followRedirects = f;
381+
}

src/include/NetworkClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ class NetworkClient
5757
uint8_t *downloadFileHTTPS(const char *url, int32_t *defaultLen);
5858
uint8_t *downloadFile(WiFiClient *url, int32_t len);
5959

60+
void setFollowRedirects(followRedirects_t f);
61+
6062
private:
6163
WiFiClientSecure *client;
64+
followRedirects_t followRedirects;
6265
char *getHostFromURL(const char *urlToGetHostFrom);
6366
char *getPathToResourceFromURL(const char *urlToGetPathToResourceFrom);
6467
};

0 commit comments

Comments
 (0)