Skip to content

Commit ba6cc06

Browse files
authored
Improve handling of lowercase HTTP response headers (#65)
1 parent b1a0013 commit ba6cc06

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [2.2.1] - 2025-09-10
2+
- Improve handling of lowercase HTTP response headers.
3+
14
## [2.2.0] - 2023-05-11
25
- Switch to dual licensing under AGPL-3.0 or MIT licenses.
36

src/Client/Response.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public function __construct(
2828
$this->body = $body;
2929
$this->headers = $headers;
3030

31+
// Support case insensitve HTTP header names (Content-Type vs content-type)
32+
$lowercase_headers = array_change_key_case($this->headers, CASE_LOWER);
33+
3134
// Store decoded JSON data, if present
3235
if (
33-
!empty( $this->headers['Content-Type'] )
34-
&& mb_strpos( $this->headers['Content-Type'][0], 'application/json;' ) !== false
36+
!empty( $lowercase_headers['content-type'] )
37+
&& mb_strpos( $lowercase_headers['content-type'][0], 'application/json;' ) !== false
3538
) {
3639
$this->data = json_decode( $this->body, true );
3740

@@ -81,4 +84,3 @@ public function hasError()
8184
return !empty( $this->getError() );
8285
}
8386
}
84-

0 commit comments

Comments
 (0)