| 1489 | } |
| 1490 | |
| 1491 | void HTTPClient::setCookie(String date, String headerValue) { |
| 1492 | if (!_cookieJar) { |
| 1493 | return; |
| 1494 | } |
| 1495 | #define HTTP_TIME_PATTERN "%a, %d %b %Y %H:%M:%S" |
| 1496 | |
| 1497 | Cookie cookie; |
| 1498 | String value; |
| 1499 | int pos1, pos2; |
| 1500 | |
| 1501 | struct tm tm; |
| 1502 | strptime(date.c_str(), HTTP_TIME_PATTERN, &tm); |
| 1503 | cookie.date = mktime(&tm); |
| 1504 | |
| 1505 | pos1 = headerValue.indexOf('='); |
| 1506 | pos2 = headerValue.indexOf(';'); |
| 1507 | |
| 1508 | if (pos1 >= 0 && pos2 > pos1) { |
| 1509 | cookie.name = headerValue.substring(0, pos1); |
| 1510 | cookie.value = headerValue.substring(pos1 + 1, pos2); |
| 1511 | } else { |
| 1512 | return; // invalid cookie header |
| 1513 | } |
| 1514 | |
| 1515 | // only Cookie Attributes are case insensitive from this point on |
| 1516 | headerValue.toLowerCase(); |
| 1517 | |
| 1518 | // expires |
| 1519 | if (headerValue.indexOf("expires=") >= 0) { |
| 1520 | pos1 = headerValue.indexOf("expires=") + strlen("expires="); |
| 1521 | pos2 = headerValue.indexOf(';', pos1); |
| 1522 | |
| 1523 | if (pos2 > pos1) { |
| 1524 | value = headerValue.substring(pos1, pos2); |
| 1525 | } else { |
| 1526 | value = headerValue.substring(pos1); |
| 1527 | } |
| 1528 | |
| 1529 | strptime(value.c_str(), HTTP_TIME_PATTERN, &tm); |
| 1530 | cookie.expires.date = mktime(&tm); |
| 1531 | cookie.expires.valid = true; |
| 1532 | } |
| 1533 | |
| 1534 | // max-age |
| 1535 | if (headerValue.indexOf("max-age=") >= 0) { |
| 1536 | pos1 = headerValue.indexOf("max-age=") + strlen("max-age="); |
| 1537 | pos2 = headerValue.indexOf(';', pos1); |
| 1538 | |
| 1539 | if (pos2 > pos1) { |
| 1540 | value = headerValue.substring(pos1, pos2); |
| 1541 | } else { |
| 1542 | value = headerValue.substring(pos1); |
| 1543 | } |
| 1544 | |
| 1545 | cookie.max_age.duration = value.toInt(); |
| 1546 | cookie.max_age.valid = true; |
| 1547 | } |
| 1548 |
nothing calls this directly
no test coverage detected