From beda1427d2bf45ed7e7d76f5b9c104b71b7be42c Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Wed, 12 Jun 2024 17:37:19 -0400 Subject: [PATCH] Ensure http client headers are properly serialized --- src/mantle/http-client/class-response.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mantle/http-client/class-response.php b/src/mantle/http-client/class-response.php index 93e726b0..a259a4a0 100644 --- a/src/mantle/http-client/class-response.php +++ b/src/mantle/http-client/class-response.php @@ -15,6 +15,7 @@ use SimpleXMLElement; use WP_Error; use WP_Http_Cookie; +use WpOrg\Requests\Utility\CaseInsensitiveDictionary; use function Mantle\Support\Helpers\collect; use function Mantle\Support\Helpers\data_get; @@ -41,6 +42,11 @@ class Response implements ArrayAccess { * @param array $response Raw response from `wp_remote_request()`. */ public function __construct( protected array $response ) { + // Serialize the headers from a CaseInsensitiveDictionary to an array. + if ( isset( $this->response['headers'] ) && $this->response['headers'] instanceof CaseInsensitiveDictionary ) { + $this->response['headers'] = $this->response['headers']->getAll(); + } + // Format the headers to be lower-case. $this->response['headers'] = array_change_key_case( (array) ( $this->response['headers'] ?? [] ) ); }