Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0f79d09

Browse filesBrowse files
Toflarfabpot
authored andcommitted
Fixed Request::__toString ignoring cookies
1 parent 277219d commit 0f79d09
Copy full SHA for 0f79d09

File tree

2 files changed

+24
-2
lines changed
Filter options

2 files changed

+24
-2
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,21 @@ public function __toString()
496496
return trigger_error($e, E_USER_ERROR);
497497
}
498498

499+
$cookieHeader = '';
500+
$cookies = array();
501+
502+
foreach ($this->cookies as $k => $v) {
503+
$cookies[] = $k.'='.$v;
504+
}
505+
506+
if (!empty($cookies)) {
507+
$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
508+
}
509+
499510
return
500511
sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
501-
$this->headers."\r\n".
512+
$this->headers.
513+
$cookieHeader."\r\n".
502514
$content;
503515
}
504516

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,18 @@ public function testToString()
14541454
$request = new Request();
14551455

14561456
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
1457+
$request->cookies->set('Foo', 'Bar');
14571458

1458-
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $request->__toString());
1459+
$asString = (string) $request;
1460+
1461+
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $asString);
1462+
$this->assertContains('Cookie: Foo=Bar', $asString);
1463+
1464+
$request->cookies->set('Another', 'Cookie');
1465+
1466+
$asString = (string) $request;
1467+
1468+
$this->assertContains('Cookie: Foo=Bar; Another=Cookie', $asString);
14591469
}
14601470

14611471
public function testIsMethod()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.