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 c245f87

Browse filesBrowse files
committed
[HttpKernel] Continuation of #20599 for 3.1
1 parent 6fddb75 commit c245f87
Copy full SHA for c245f87

File tree

Expand file treeCollapse file tree

2 files changed

+17
-48
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-48
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
+15-46Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php
+2-2Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.