Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 257a856

Browse files
committed
[WebProfilerBundle] Display multiple HTTP headers in WDT
1 parent 3e874dc commit 257a856

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\KernelEvents;
2018
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
2119
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -40,12 +38,8 @@ public function __construct()
4038
public function collect(Request $request, Response $response, \Exception $exception = null)
4139
{
4240
$responseHeaders = $response->headers->all();
43-
$cookies = array();
4441
foreach ($response->headers->getCookies() as $cookie) {
45-
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
46-
}
47-
if (count($cookies) > 0) {
48-
$responseHeaders['Set-Cookie'] = $cookies;
42+
$responseHeaders['set-cookie'][] = (string) $cookie;
4943
}
5044

5145
// attributes are serialized and as they can be anything, they need to be converted to strings.
@@ -121,6 +115,18 @@ public function collect(Request $request, Response $response, \Exception $except
121115
$this->data['request_request']['_password'] = '******';
122116
}
123117

118+
foreach ($this->data as $key => $value) {
119+
if (!is_array($value)) {
120+
continue;
121+
}
122+
if ('request_headers' === $key || 'response_headers' === $key) {
123+
$value = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
124+
}
125+
if ('request_server' !== $key && 'request_cookies' !== $key) {
126+
$this->data[$key] = $value;
127+
}
128+
}
129+
124130
if (isset($this->controllers[$request])) {
125131
$controller = $this->controllers[$request];
126132
if (is_array($controller)) {
@@ -183,7 +189,7 @@ public function getRequestQuery()
183189

184190
public function getRequestHeaders()
185191
{
186-
return new HeaderBag($this->data['request_headers']);
192+
return new ParameterBag($this->data['request_headers']);
187193
}
188194

189195
public function getRequestServer()
@@ -203,7 +209,7 @@ public function getRequestAttributes()
203209

204210
public function getResponseHeaders()
205211
{
206-
return new ResponseHeaderBag($this->data['response_headers']);
212+
return new ParameterBag($this->data['response_headers']);
207213
}
208214

209215
public function getSessionMetadata()
@@ -302,41 +308,4 @@ public function getName()
302308
{
303309
return 'request';
304310
}
305-
306-
private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)
307-
{
308-
$cookie = sprintf('%s=%s', $name, urlencode($value));
309-
310-
if (0 !== $expires) {
311-
if (is_numeric($expires)) {
312-
$expires = (int) $expires;
313-
} elseif ($expires instanceof \DateTime) {
314-
$expires = $expires->getTimestamp();
315-
} else {
316-
$tmp = strtotime($expires);
317-
if (false === $tmp || -1 == $tmp) {
318-
throw new \InvalidArgumentException(sprintf('The "expires" cookie parameter is not valid (%s).', $expires));
319-
}
320-
$expires = $tmp;
321-
}
322-
323-
$cookie .= '; expires='.str_replace('+0000', '', \DateTime::createFromFormat('U', $expires, new \DateTimeZone('GMT'))->format('D, d-M-Y H:i:s T'));
324-
}
325-
326-
if ($domain) {
327-
$cookie .= '; domain='.$domain;
328-
}
329-
330-
$cookie .= '; path='.$path;
331-
332-
if ($secure) {
333-
$cookie .= '; secure';
334-
}
335-
336-
if ($httponly) {
337-
$cookie .= '; httponly';
338-
}
339-
340-
return $cookie;
341-
}
342311
}

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

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

3333
$this->assertSame('request', $c->getName());
34-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getRequestHeaders());
34+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestHeaders());
3535
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestServer());
3636
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestCookies());
3737
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
@@ -45,7 +45,7 @@ public function testCollect()
4545
$this->assertRegExp('/Resource\(stream#\d+\)/', $attributes->get('resource'));
4646
$this->assertSame('Object(stdClass)', $attributes->get('object'));
4747

48-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getResponseHeaders());
48+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());
4949
$this->assertSame('OK', $c->getStatusText());
5050
$this->assertSame(200, $c->getStatusCode());
5151
$this->assertSame('application/json', $c->getContentType());

0 commit comments

Comments
 (0)