Skip to content

Commit

Permalink
Ensure http client headers are properly serialized
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Jun 12, 2024
1 parent 84fe165 commit beda142
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mantle/http-client/class-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'] ?? [] ) );
}
Expand Down

0 comments on commit beda142

Please sign in to comment.