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
This commit is contained in:
commit
73a7169a5d
@ -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\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
|
||||
@ -42,12 +40,8 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
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;
|
||||
}
|
||||
|
||||
// attributes are serialized and as they can be anything, they need to be converted to strings.
|
||||
@ -125,6 +119,18 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->controllers[$request])) {
|
||||
$this->data['controller'] = $this->parseController($this->controllers[$request]);
|
||||
unset($this->controllers[$request]);
|
||||
@ -170,7 +176,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
|
||||
public function getRequestHeaders()
|
||||
{
|
||||
return new HeaderBag($this->data['request_headers']);
|
||||
return new ParameterBag($this->data['request_headers']);
|
||||
}
|
||||
|
||||
public function getRequestServer()
|
||||
@ -190,7 +196,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return new ResponseHeaderBag($this->data['response_headers']);
|
||||
return new ParameterBag($this->data['response_headers']);
|
||||
}
|
||||
|
||||
public function getSessionMetadata()
|
||||
@ -376,41 +382,4 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
|
||||
return is_string($controller) ? $controller : 'n/a';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
$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);
|
||||
@ -50,7 +50,7 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
$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());
|
||||
|
Reference in New Issue
Block a user