Fixed Request::__toString ignoring cookies

This commit is contained in:
Yanick Witschi 2018-01-15 16:19:42 +01:00 committed by Fabien Potencier
parent 277219d0a7
commit 0f79d09a10
2 changed files with 24 additions and 2 deletions

View File

@ -496,9 +496,21 @@ class Request
return trigger_error($e, E_USER_ERROR);
}
$cookieHeader = '';
$cookies = array();
foreach ($this->cookies as $k => $v) {
$cookies[] = $k.'='.$v;
}
if (!empty($cookies)) {
$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
}
return
sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
$this->headers."\r\n".
$this->headers.
$cookieHeader."\r\n".
$content;
}

View File

@ -1454,8 +1454,18 @@ class RequestTest extends TestCase
$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
$request->cookies->set('Foo', 'Bar');
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $request->__toString());
$asString = (string) $request;
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $asString);
$this->assertContains('Cookie: Foo=Bar', $asString);
$request->cookies->set('Another', 'Cookie');
$asString = (string) $request;
$this->assertContains('Cookie: Foo=Bar; Another=Cookie', $asString);
}
public function testIsMethod()