Skip to content

Commit 270699f

Browse files
committed
Supports more cookie date formats in the Cookie Plugin
Fix php-http#46
1 parent 33b6d65 commit 270699f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Added
6+
7+
- Supports more cookie date formats in the Cookie Plugin
8+
59
### Deprecated
610

711
- The `debug_plugins` option for `PluginClient` is deprecated and will be removed in 2.0. Use the decorator design pattern instead like in [ProfilePlugin](https://github.com/php-http/HttplugBundle/blob/de33f9c14252f22093a5ec7d84f17535ab31a384/Collector/ProfilePlugin.php).

composer.json

Lines changed: 1 addition & 1 deletion
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@dev",
1818
"symfony/options-resolver": "^2.6 || ^3.0"
1919
},
2020
"require-dev": {

src/Plugin/CookiePlugin.php

Lines changed: 8 additions & 4 deletions
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
break;

0 commit comments

Comments
 (0)