Skip to content

[WebProfilerBundle] Display multiple HTTP headers in WDT #20599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
namespace Symfony\Component\HttpKernel\DataCollector;

use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand All @@ -40,12 +38,8 @@ public function __construct()
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
if (count($cookies) > 0) {
$responseHeaders['Set-Cookie'] = $cookies;
$responseHeaders['set-cookie'][] = (string) $cookie;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above should apply to 3.1 & 3.2 as well.

In master we can remove this block due #20569. I covered this with #20567 and should be a separate PR otherwise (basically forgotten in #20569).


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

foreach ($this->data as $key => $value) {
if (!is_array($value)) {
continue;
}
if ('request_headers' === $key || 'response_headers' === $key) {
$value = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
}
if ('request_server' !== $key && 'request_cookies' !== $key) {
$this->data[$key] = $value;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above should apply to 3.1 as well.

In master this is already applied due #20595.

if (isset($this->controllers[$request])) {
$controller = $this->controllers[$request];
if (is_array($controller)) {
Expand Down Expand Up @@ -183,7 +189,7 @@ public function getRequestQuery()

public function getRequestHeaders()
{
return new HeaderBag($this->data['request_headers']);
return new ParameterBag($this->data['request_headers']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, should be applied to 3.1

}

public function getRequestServer()
Expand All @@ -203,7 +209,7 @@ public function getRequestAttributes()

public function getResponseHeaders()
{
return new ResponseHeaderBag($this->data['response_headers']);
return new ParameterBag($this->data['response_headers']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, should be applied to 3.1

}

public function getSessionMetadata()
Expand Down Expand Up @@ -302,41 +308,4 @@ public function getName()
{
return 'request';
}

private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)
{
$cookie = sprintf('%s=%s', $name, urlencode($value));

if (0 !== $expires) {
if (is_numeric($expires)) {
$expires = (int) $expires;
} elseif ($expires instanceof \DateTime) {
$expires = $expires->getTimestamp();
} else {
$tmp = strtotime($expires);
if (false === $tmp || -1 == $tmp) {
throw new \InvalidArgumentException(sprintf('The "expires" cookie parameter is not valid (%s).', $expires));
}
$expires = $tmp;
}

$cookie .= '; expires='.str_replace('+0000', '', \DateTime::createFromFormat('U', $expires, new \DateTimeZone('GMT'))->format('D, d-M-Y H:i:s T'));
}

if ($domain) {
$cookie .= '; domain='.$domain;
}

$cookie .= '; path='.$path;

if ($secure) {
$cookie .= '; secure';
}

if ($httponly) {
$cookie .= '; httponly';
}

return $cookie;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testCollect()
$attributes = $c->getRequestAttributes();

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

$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getResponseHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());
$this->assertSame('OK', $c->getStatusText());
$this->assertSame(200, $c->getStatusCode());
$this->assertSame('application/json', $c->getContentType());
Expand Down