Skip to content

Commit 0245571

Browse files
authored
Merge pull request #76 from aaa2000/cookie-date
Supports more cookie date formats in the Cookie Plugin
2 parents 75d89f8 + d58085d commit 0245571

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `PluginClientFactory` to create `PluginClient` instances.
99
- Added new option 'delay' for `RetryPlugin`.
1010
- Added new option 'decider' for `RetryPlugin`.
11+
- Supports more cookie date formats in the Cookie Plugin
1112

1213
### Changed
1314

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": ">=5.4",
1515
"php-http/httplug": "^1.1",
1616
"php-http/message-factory": "^1.0",
17-
"php-http/message": "^1.2",
17+
"php-http/message": "^1.6",
1818
"symfony/options-resolver": "^2.6 || ^3.0"
1919
},
2020
"require-dev": {

src/Plugin/CookiePlugin.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Http\Client\Exception\TransferException;
77
use Http\Message\Cookie;
88
use Http\Message\CookieJar;
9+
use Http\Message\CookieUtil;
10+
use Http\Message\Exception\UnexpectedValueException;
911
use Psr\Http\Message\RequestInterface;
1012
use Psr\Http\Message\ResponseInterface;
1113

@@ -114,15 +116,17 @@ private function createCookie(RequestInterface $request, $setCookie)
114116

115117
switch (strtolower($key)) {
116118
case 'expires':
117-
$expires = \DateTime::createFromFormat(\DateTime::COOKIE, $value);
118-
119-
if (true !== ($expires instanceof \DateTime)) {
119+
try {
120+
$expires = CookieUtil::parseDate($value);
121+
} catch (UnexpectedValueException $e) {
120122
throw new TransferException(
121123
sprintf(
122124
'Cookie header `%s` expires value `%s` could not be converted to date',
123125
$name,
124126
$value
125-
)
127+
),
128+
null,
129+
$e
126130
);
127131
}
128132

0 commit comments

Comments
 (0)