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 \KernelEvents ;
20
18
use Symfony \Component \HttpKernel \Event \FilterControllerEvent ;
21
19
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
@@ -40,12 +38,8 @@ public function __construct()
40
38
public function collect (Request $ request , Response $ response , \Exception $ exception = null )
41
39
{
42
40
$ responseHeaders = $ response ->headers ->all ();
43
- $ cookies = array ();
44
41
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 ;
49
43
}
50
44
51
45
// 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
121
115
$ this ->data ['request_request ' ]['_password ' ] = '****** ' ;
122
116
}
123
117
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
+
124
130
if (isset ($ this ->controllers [$ request ])) {
125
131
$ controller = $ this ->controllers [$ request ];
126
132
if (is_array ($ controller )) {
@@ -183,7 +189,7 @@ public function getRequestQuery()
183
189
184
190
public function getRequestHeaders ()
185
191
{
186
- return new HeaderBag ($ this ->data ['request_headers ' ]);
192
+ return new ParameterBag ($ this ->data ['request_headers ' ]);
187
193
}
188
194
189
195
public function getRequestServer ()
@@ -203,7 +209,7 @@ public function getRequestAttributes()
203
209
204
210
public function getResponseHeaders ()
205
211
{
206
- return new ResponseHeaderBag ($ this ->data ['response_headers ' ]);
212
+ return new ParameterBag ($ this ->data ['response_headers ' ]);
207
213
}
208
214
209
215
public function getSessionMetadata ()
@@ -302,41 +308,4 @@ public function getName()
302
308
{
303
309
return 'request ' ;
304
310
}
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
- }
342
311
}
0 commit comments