Skip to content

Commit 88e2975

Browse files
authored
cookie jar
1 parent c0d1c25 commit 88e2975

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

libraries/HTTPClient/src/HTTPClient.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include <WiFiClient.h>
3737
#include <WiFiClientSecure.h>
3838

39+
/// Cookie jar support
40+
#include <vector>
41+
3942
#define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000)
4043

4144
/// HTTP client errors
@@ -144,6 +147,28 @@ class TransportTraits;
144147
typedef std::unique_ptr<TransportTraits> TransportTraitsPtr;
145148
#endif
146149

150+
// cookie jar support
151+
typedef struct {
152+
String host; // host which tries to set the cookie
153+
time_t date; // timestamp of the response that set the cookie
154+
String name;
155+
String value;
156+
String domain;
157+
String path = "";
158+
struct {
159+
time_t date = 0;
160+
bool valid = false;
161+
} expires;
162+
struct {
163+
time_t duration = 0;
164+
bool valid = false;
165+
} max_age;
166+
bool http_only = false;
167+
bool secure = false;
168+
} Cookie;
169+
typedef std::vector<Cookie> CookieJar;
170+
171+
147172
class HTTPClient
148173
{
149174
public:
@@ -217,6 +242,11 @@ class HTTPClient
217242

218243
static String errorToString(int error);
219244

245+
/// Cookie jar support
246+
void setCookieJar(CookieJar* cookieJar);
247+
void resetCookieJar();
248+
void clearAllCookies();
249+
220250
protected:
221251
struct RequestArgument {
222252
String key;
@@ -232,6 +262,9 @@ class HTTPClient
232262
int handleHeaderResponse();
233263
int writeToStreamDataBlock(Stream * stream, int len);
234264

265+
/// Cookie jar support
266+
void setCookie(String date, String headerValue);
267+
bool generateCookieString(String *cookieString);
235268

236269
#ifdef HTTPCLIENT_1_1_COMPATIBLE
237270
TransportTraitsPtr _transportTraits;
@@ -267,6 +300,10 @@ class HTTPClient
267300
uint16_t _redirectLimit = 10;
268301
String _location;
269302
transferEncoding_t _transferEncoding = HTTPC_TE_IDENTITY;
303+
304+
/// Cookie jar support
305+
CookieJar* _cookieJar = nullptr;
306+
270307
};
271308

272309

0 commit comments

Comments
 (0)