Skip to content

Commit

Permalink
Fix cookies sending by ResponseEmitter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jan 1, 2017
1 parent 74015d6 commit 4efbfcd
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Http/ResponseEmitter.php
Expand Up @@ -162,9 +162,14 @@ protected function emitStatusLine(ResponseInterface $response)
*/
protected function emitHeaders(ResponseInterface $response)
{
$cookies = [];
if (method_exists($response, 'cookie')) {
$cookies = $response->cookie();
}

foreach ($response->getHeaders() as $name => $values) {
if (strtolower($name) === 'set-cookie') {
$this->emitCookies($values);
$cookies = array_merge($cookies, $values);
continue;
}
$first = true;
Expand All @@ -177,6 +182,8 @@ protected function emitHeaders(ResponseInterface $response)
$first = false;
}
}

$this->emitCookies($cookies);
}

/**
Expand All @@ -187,7 +194,20 @@ protected function emitHeaders(ResponseInterface $response)
*/
protected function emitCookies(array $cookies)
{
foreach ((array)$cookies as $cookie) {
foreach ($cookies as $cookie) {
if (is_array($cookie)) {
setcookie(
$cookie['name'],
$cookie['value'],
$cookie['expire'],
$cookie['path'],
$cookie['domain'],
$cookie['secure'],
$cookie['httpOnly']
);
continue;
}

if (strpos($cookie, '";"') !== false) {
$cookie = str_replace('";"', "{__cookie_replace__}", $cookie);
$parts = str_replace("{__cookie_replace__}", '";"', explode(';', $cookie));
Expand Down

0 comments on commit 4efbfcd

Please sign in to comment.