1212namespace Symfony \Component \HttpKernel \DataCollector ;
1313
1414use Symfony \Component \HttpFoundation \ParameterBag ;
15- use Symfony \Component \HttpFoundation \HeaderBag ;
1615use Symfony \Component \HttpFoundation \Request ;
1716use Symfony \Component \HttpFoundation \Response ;
18- use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
1917use Symfony \Component \HttpKernel \Event \FilterResponseEvent ;
2018use Symfony \Component \HttpKernel \KernelEvents ;
2119use 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}
0 commit comments