36
36
#include < WiFiClient.h>
37
37
#include < WiFiClientSecure.h>
38
38
39
+ // / Cookie jar support
40
+ #include < vector>
41
+
39
42
#define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000 )
40
43
41
44
// / HTTP client errors
@@ -144,6 +147,28 @@ class TransportTraits;
144
147
typedef std::unique_ptr<TransportTraits> TransportTraitsPtr;
145
148
#endif
146
149
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
+
147
172
class HTTPClient
148
173
{
149
174
public:
@@ -217,6 +242,11 @@ class HTTPClient
217
242
218
243
static String errorToString (int error);
219
244
245
+ // / Cookie jar support
246
+ void setCookieJar (CookieJar* cookieJar);
247
+ void resetCookieJar ();
248
+ void clearAllCookies ();
249
+
220
250
protected:
221
251
struct RequestArgument {
222
252
String key;
@@ -232,6 +262,9 @@ class HTTPClient
232
262
int handleHeaderResponse ();
233
263
int writeToStreamDataBlock (Stream * stream, int len);
234
264
265
+ // / Cookie jar support
266
+ void setCookie (String date, String headerValue);
267
+ bool generateCookieString (String *cookieString);
235
268
236
269
#ifdef HTTPCLIENT_1_1_COMPATIBLE
237
270
TransportTraitsPtr _transportTraits;
@@ -267,6 +300,10 @@ class HTTPClient
267
300
uint16_t _redirectLimit = 10 ;
268
301
String _location;
269
302
transferEncoding_t _transferEncoding = HTTPC_TE_IDENTITY;
303
+
304
+ // / Cookie jar support
305
+ CookieJar* _cookieJar = nullptr ;
306
+
270
307
};
271
308
272
309
0 commit comments