Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit06ef68f

Browse files
committed
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-------0f79d09 Fixed Request::__toString ignoring cookies
2 parents277219d +0f79d09 commit06ef68f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,21 @@ public function __toString()
496496
returntrigger_error($e,E_USER_ERROR);
497497
}
498498

499+
$cookieHeader ='';
500+
$cookies =array();
501+
502+
foreach ($this->cookiesas$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‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,18 @@ public function testToString()
14541454
$request =newRequest();
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
publicfunctiontestIsMethod()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp