@@ -1543,6 +1543,10 @@ void HTTPClient::clearAllCookies()
1543
1543
1544
1544
void HTTPClient::setCookie (String date, String headerValue)
1545
1545
{
1546
+ if (!_cookieJar)
1547
+ {
1548
+ return ;
1549
+ }
1546
1550
#define HTTP_TIME_PATTERN " %a, %d %b %Y %H:%M:%S"
1547
1551
1548
1552
Cookie cookie;
@@ -1574,7 +1578,7 @@ void HTTPClient::setCookie(String date, String headerValue)
1574
1578
value = headerValue.substring (pos1, pos2);
1575
1579
else
1576
1580
value = headerValue.substring (pos1);
1577
-
1581
+
1578
1582
strptime (value.c_str (), HTTP_TIME_PATTERN, &tm );
1579
1583
cookie.expires .date = mktime (&tm );
1580
1584
cookie.expires .valid = true ;
@@ -1589,7 +1593,7 @@ void HTTPClient::setCookie(String date, String headerValue)
1589
1593
value = headerValue.substring (pos1, pos2);
1590
1594
else
1591
1595
value = headerValue.substring (pos1);
1592
-
1596
+
1593
1597
cookie.max_age .duration = value.toInt ();
1594
1598
cookie.max_age .valid = true ;
1595
1599
}
@@ -1639,10 +1643,10 @@ void HTTPClient::setCookie(String date, String headerValue)
1639
1643
// overwrite or delete cookie in/from cookie jar
1640
1644
time_t now_local = time (NULL );
1641
1645
time_t now_gmt = mktime (gmtime (&now_local));
1642
-
1646
+
1643
1647
bool found = false ;
1644
1648
1645
- for (auto c = _cookieJar->begin (); c != _cookieJar->end (); ++c) {
1649
+ for (auto c = _cookieJar->begin (); c != _cookieJar->end (); ++c) {
1646
1650
if (c->domain == cookie.domain && c->name == cookie.name ) {
1647
1651
// when evaluating, max-age takes precedence over expires if both are defined
1648
1652
if ((cookie.max_age .valid && ((cookie.date + cookie.max_age .duration ) < now_gmt)) || cookie.max_age .duration <= 0
@@ -1670,6 +1674,10 @@ bool HTTPClient::generateCookieString(String *cookieString)
1670
1674
*cookieString = " " ;
1671
1675
bool found = false ;
1672
1676
1677
+ if (!_cookieJar)
1678
+ {
1679
+ return false ;
1680
+ }
1673
1681
for (auto c = _cookieJar->begin (); c != _cookieJar->end (); ++c) {
1674
1682
if ((c->max_age .valid && ((c->date + c->max_age .duration ) < now_gmt)) || (!c->max_age .valid && c->expires .valid && c->expires .date < now_gmt)) {
1675
1683
_cookieJar->erase (c);
@@ -1682,5 +1690,6 @@ bool HTTPClient::generateCookieString(String *cookieString)
1682
1690
found = true ;
1683
1691
}
1684
1692
}
1693
+
1685
1694
return found;
1686
1695
}
0 commit comments