8000 bug #20999 [HttpKernel] Continuation of #20599 for 3.1 (ro0NL) · symfony/symfony@73a7169 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73a7169

Browse files
committed
bug #20999 [HttpKernel] Continuation of #20599 for 3.1 (ro0NL)
This PR was merged into the 3.1 branch. Discussion ---------- [HttpKernel] Continuation of #20599 for 3.1 | Q | A | ------------- | --- | Branch? | 3.1 only | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> #20599 is only merged up to 2.8.. not sure if 3.1 is already EOM? Commits ------- c245f87 [HttpKernel] Continuation of #20599 for 3.1
2 parents 6fddb75 + c245f87 commit 73a7169

File tree

2 files changed

+17
-48
lines changed

2 files changed

+17
-48
lines changed

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
namespace Symfony\Component\HttpKernel\DataCollector;
1313

1414
use Symfony\Component\HttpFoundation\ParameterBag;
15-
use Symfony\Component\HttpFoundation\HeaderBag;
1615
use Symfony\Component\HttpFoundation\Request;
1716
use Symfony\Component\HttpFoundation\Response;
18-
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1917
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
2018
use Symfony\Component\HttpKernel\KernelEvents;
2119
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
@@ -42,12 +40,8 @@ public function __construct()
4240
public function collect(Request $request, Response $response, \Exception $exception = null)
4341
{
4442
$responseHeaders = $response->headers->all();
45-
$cookies = array();
4643
foreach ($response->headers->getCookies() as $cookie) {
47-
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
48-
}
49-
if (count($cookies) > 0) {
50-
$responseHeaders['Set-Cookie'] = $cookies;
44+
$responseHeaders['set-cookie'][] = (string) $cookie;
5145
}
5246

5347
// attributes are serialized and as they can be anything, they need to be converted to strings.
@@ -125,6 +119,18 @@ public function collect(Request $request, Response $response, \Exception $except
125119
$this->data['request_request']['_password'] = '******';
126120
}
127121

122+
foreach ($this->data as $key => $value) {
123+
if (!is_array($value)) {
124+
continue;
125+
}
126+
if ('request_headers' === $key || 'response_headers' === $key) {
127+
$value = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
128+
}
129+
if ('request_server' !== $key && 'request_cookies' !== $key) {
130+
$this->data[$key] = $value;
131+
}
132+
}
133+
128134
if (isset($this->controllers[$request])) {
129135
$this->data['controller'] = $this->parseController($this->controllers[$request]);
130136
unset($this->controllers[$request]);
@@ -170,7 +176,7 @@ public function getRequestQuery()
170176

171177
public function getRequestHeaders()
172178
{
173-
return new HeaderBag($this->data['request_headers']);
179+
return new ParameterBag($this->data['request_headers']);
174180
}
175181

176182
public function getRequestServer()
@@ -190,7 +196,7 @@ public function getRequestAttributes()
190196

191197
public function getResponseHeaders()
192198
{
193-
return new ResponseHeaderBag($this->data['response_headers']);
199+
return new ParameterBag($this->data['response_headers']);
194200
}
195201

196202
public function getSessionMetadata()
@@ -376,41 +382,4 @@ protected function parseController($controller)
376382

377383
return is_string($controller) ? $controller : 'n/a';
378384
}
379-
380-
private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)
381-
{
382-
$cookie = sprintf('%s=%s', $name, urlencode($value));
383-
384-
if (0 !== $expires) {
385-
if (is_numeric($expires)) {
386-
$expires = (int) $expires;
387-
} elseif ($expires instanceof \DateTime) {
388-
$expires = $expires->getTimestamp();
389-
} else {
390-
$tmp = strtotime($expires);
391-
if (false === $tmp || -1 == $tmp) {
392-
throw new \InvalidArgumentException(sprintf('The "expires" cookie parameter is not valid (%s).', $expires));
393-
}
394-
$expires = $tmp;
395-
}
396-
397-
$cookie .= '; expires='.str_replace('+0000', '', \DateTime::createFromFormat('U', $expires, new \DateTimeZone('GMT'))->format('D, d-M-Y H:i:s T'));
398-
}
399-
400-
if ($domain) {
401-
$cookie .= '; domain='.$domain;
402-
}
403-
404-
$cookie .= '; path='.$path;
405-
406-
if ($secure) {
407-
$cookie .= '; secure';
408-
}
409-
410-
if ($httponly) {
411-
$cookie .= '; httponly';
412-
}
413-
414-
return $cookie;
415-
}
416385
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testCollect()
3636
$attributes = $c->getRequestAttributes();
3737

3838
$this->assertSame('request', $c->getName());
39-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getRequestHeaders());
39+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestHeaders());
4040
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestServer());
4141
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestCookies());
4242
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
@@ -50,7 +50,7 @@ public function testCollect()
5050
$this->assertRegExp('/Resource\(stream#\d+\)/', $attributes->get('resource'));
5151
$this->assertSame('Object(stdClass)', $attributes->get('object'));
5252

53-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getResponseHeaders());
53+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());
5454
$this->assertSame('OK', $c->getStatusText());
5555
$this->assertSame(200, $c->getStatusCode());
5656
$this->assertSame('application/json', $c->getContentType());

0 commit comments

Comments
 (0)
0