@@ -33,10 +33,16 @@ class Connection
33
33
private $ headers = [];
34
34
35
35
/**
36
- * @var array<string, string> Hash of headers from HTTP response
36
+ * @var array<string, string> Hash of headers from HTTP response. Will overwrite headers with duplicates keys eg. it is
37
+ * common for a response to have multiple 'set-cookie' headers and only the last one will be kept.
37
38
*/
38
39
private $ responseHeaders = [];
39
40
41
+ /**
42
+ * @var array<string, string[]> Returns all response headers grouped by their header key. This preserves all response headers.
43
+ */
44
+ private array $ responseHeadersList = [];
45
+
40
46
/**
41
47
* The status line of the response.
42
48
* @var string
@@ -285,6 +291,8 @@ private function initializeRequest()
285
291
{
286
292
$ this ->responseBody = '' ;
287
293
$ this ->responseHeaders = [];
294
+ $ this ->responseHeadersList = [];
295
+ $ this ->responseStatusLine = '' ;
288
296
$ this ->lastError = false ;
289
297
$ this ->addHeader ('Accept ' , $ this ->getContentType ());
290
298
@@ -539,6 +547,8 @@ private function parseHeader($curl, $headers)
539
547
} else {
540
548
$ parts = explode (': ' , $ headers );
541
549
if (isset ($ parts [1 ])) {
550
+ $ key = strtolower (trim ($ parts [0 ]));
551
+ $ this ->responseHeadersList [$ key ][] = trim ($ parts [1 ]);
542
552
$ this ->responseHeaders [$ parts [0 ]] = trim ($ parts [1 ]);
543
553
}
544
554
}
@@ -596,14 +606,23 @@ public function getHeader($header)
596
606
}
597
607
598
608
/**
599
- * Return the full list of response headers
609
+ * Return an associative array of response headers. Will overwrite headers that share the same key.
600
610
* @return array<string, string>
601
611
*/
602
612
public function getHeaders ()
603
613
{
604
614
return $ this ->responseHeaders ;
605
615
}
606
616
617
+ /**
618
+ * Return full list of response headers as an array of strings. Preserves headers with duplicate keys.
619
+ * @return array<string, string[]>
620
+ */
621
+ public function getHeadersList ()
622
+ {
623
+ return $ this ->responseHeadersList ;
624
+ }
625
+
607
626
/**
608
627
* Close the cURL resource when the instance is garbage collected
609
628
*/
0 commit comments