bug #25799 Fixed Request::__toString ignoring cookies (Toflar)

This PR was squashed before being merged into the 2.7 branch (closes #25799).

Discussion
----------

Fixed Request::__toString ignoring cookies

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

`Request::__toString()` ignored cookie values which caused me some headaches during a debugging session 😄

Commits
-------

0f79d09a10 Fixed Request::__toString ignoring cookies
This commit is contained in:
Fabien Potencier 2018-01-16 08:04:03 +01:00
commit 06ef68fae7
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()