|
|
@@ -43,6 +43,9 @@ class ResponseTransformer
|
|
|
'body' => static::getBody($response),
|
|
|
];
|
|
|
$cake = new CakeResponse($data);
|
|
|
+ foreach (static::parseCookies($response->getHeader('Set-Cookie')) as $cookie) {
|
|
|
+ $cake->cookie($cookie);
|
|
|
+ }
|
|
|
$cake->header(static::collapseHeaders($response));
|
|
|
return $cake;
|
|
|
}
|
|
|
@@ -64,6 +67,53 @@ class ResponseTransformer
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Parse the Set-Cookie headers in a PSR7 response
|
|
|
+ * into the format CakePHP expects.
|
|
|
+ *
|
|
|
+ * @param array $cookieHeader A list of Set-Cookie headers.
|
|
|
+ * @return array Parsed cookie data.
|
|
|
+ */
|
|
|
+ protected static function parseCookies(array $cookieHeader)
|
|
|
+ {
|
|
|
+ $cookies = [];
|
|
|
+ foreach ($cookieHeader as $cookie) {
|
|
|
+ if (strpos($cookie, '";"') !== false) {
|
|
|
+ $cookie = str_replace('";"', "{__cookie_replace__}", $cookie);
|
|
|
+ $parts = preg_split('/\;[ \t]*/', $cookie);
|
|
|
+ $parts = str_replace("{__cookie_replace__}", '";"', $parts);
|
|
|
+ } else {
|
|
|
+ $parts = preg_split('/\;[ \t]*/', $cookie);
|
|
|
+ }
|
|
|
+
|
|
|
+ list($name, $value) = explode('=', array_shift($parts), 2);
|
|
|
+ $parsed = compact('name', 'value');
|
|
|
+
|
|
|
+ foreach ($parts as $part) {
|
|
|
+ if (strpos($part, '=') !== false) {
|
|
|
+ list($key, $value) = explode('=', $part);
|
|
|
+ } else {
|
|
|
+ $key = $part;
|
|
|
+ $value = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $key = strtolower($key);
|
|
|
+ if ($key === 'httponly') {
|
|
|
+ $key = 'httpOnly';
|
|
|
+ }
|
|
|
+ if ($key === 'expires') {
|
|
|
+ $key = 'expire';
|
|
|
+ $value = strtotime($value);
|
|
|
+ }
|
|
|
+ if (!isset($parsed[$key])) {
|
|
|
+ $parsed[$key] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $cookies[] = $parsed;
|
|
|
+ }
|
|
|
+ return $cookies;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Convert a PSR7 Response headers into a flat array
|
|
|
*
|
|
|
* @param PsrResponse $response The response to convert.
|