8000 Fixed Request::__toString ignoring cookies by Toflar · Pull Request #25799 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fixed Request::__toString ignoring cookies #25799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,21 @@ public function __toString()
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;
}

Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1454,8 +1454,18 @@ public function testToString()
$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()
Expand Down
0