12
12
namespace Symfony \Component \HttpKernel \DataCollector ;
13
13
14
14
use Symfony \Component \HttpFoundation \ParameterBag ;
15
- use Symfony \Component \HttpFoundation \HeaderBag ;
16
15
use Symfony \Component \HttpFoundation \Request ;
17
16
use Symfony \Component \HttpFoundation \Response ;
18
- use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
19
17
use Symfony \Component \HttpKernel \Event \FilterResponseEvent ;
20
18
use Symfony \Component \HttpKernel \KernelEvents ;
21
19
use Symfony \Component \HttpKernel \Event \FilterControllerEvent ;
@@ -42,12 +40,8 @@ public function __construct()
42
40
public function collect (Request $ request , Response $ response , \Exception $ exception = null )
43
41
{
44
42
$ responseHeaders = $ response ->headers ->all ();
45
- $ cookies = array ();
46
43
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 ;
51
45
}
52
46
53
47
// 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
125
119
$ this ->data ['request_request ' ]['_password ' ] = '****** ' ;
126
120
}
127
121
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
+
128
134
if (isset ($ this ->controllers [$ request ])) {
129
135
$ this ->data ['controller ' ] = $ this ->parseController ($ this ->controllers [$ request ]);
130
136
unset($ this ->controllers [$ request ]);
@@ -170,7 +176,7 @@ public function getRequestQuery()
170
176
171
177
public function getRequestHeaders ()
172
178
{
173
- return new HeaderBag ($ this ->data ['request_headers ' ]);
179
+ return new ParameterBag ($ this ->data ['request_headers ' ]);
174
180
}
175
181
176
182
public function getRequestServer ()
@@ -190,7 +196,7 @@ public function getRequestAttributes()
190
196
191
197
public function getResponseHeaders ()
192
198
{
193
- return new ResponseHeaderBag ($ this ->data ['response_headers ' ]);
199
+ return new ParameterBag ($ this ->data ['response_headers ' ]);
194
200
}
195
201
196
202
public function getSessionMetadata ()
@@ -376,41 +382,4 @@ protected function parseController($controller)
376
382
377
383
return is_string ($ controller ) ? $ controller : 'n/a ' ;
378
384
}
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
- }
416
385
}
0 commit comments