@@ -33,10 +33,16 @@ class Connection
3333 private $ headers = [];
3434
3535 /**
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.
3738 */
3839 private $ responseHeaders = [];
3940
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+
4046 /**
4147 * The status line of the response.
4248 * @var string
@@ -285,6 +291,8 @@ private function initializeRequest()
285291 {
286292 $ this ->responseBody = '' ;
287293 $ this ->responseHeaders = [];
294+ $ this ->responseHeadersList = [];
295+ $ this ->responseStatusLine = '' ;
288296 $ this ->lastError = false ;
289297 $ this ->addHeader ('Accept ' , $ this ->getContentType ());
290298
@@ -539,6 +547,8 @@ private function parseHeader($curl, $headers)
539547 } else {
540548 $ parts = explode (': ' , $ headers );
541549 if (isset ($ parts [1 ])) {
550+ $ key = strtolower (trim ($ parts [0 ]));
551+ $ this ->responseHeadersList [$ key ][] = trim ($ parts [1 ]);
542552 $ this ->responseHeaders [$ parts [0 ]] = trim ($ parts [1 ]);
543553 }
544554 }
@@ -596,14 +606,23 @@ public function getHeader($header)
596606 }
597607
598608 /**
599- * Return the full list of response headers
609+ * Return an associative array of response headers. Will overwrite headers that share the same key.
600610 * @return array<string, string>
601611 */
602612 public function getHeaders ()
603613 {
604614 return $ this ->responseHeaders ;
605615 }
606616
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+
607626 /**
608627 * Close the cURL resource when the instance is garbage collected
609628 */
0 commit comments