Skip to content

Commit 58398a6

Browse files
committed
Fixed header case normalization and content type checks
Signed-off-by: takuyanakazawa <[email protected]>
1 parent 444d164 commit 58398a6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Diff for: src/OpenSearch/Serializers/SmartSerializer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ private function isJson(array $headers): bool
9393
}
9494

9595
// Check PSR-7 headers.
96-
if (array_key_exists('Content-Type', $headers)) {
97-
foreach ($headers['Content-Type'] as $type) {
96+
$lowercaseHeaders = array_change_key_case($headers, CASE_LOWER);
97+
if (array_key_exists('content-type', $lowercaseHeaders)) {
98+
foreach ($lowercaseHeaders['content-type'] as $type) {
9899
if (str_contains($type, 'json')) {
99100
return true;
100101
}

Diff for: tests/Serializers/SmartSerializerTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public function testDeserialize(): void
6868
$this->assertEquals('bar', $result['foo']);
6969
}
7070

71+
public function testDeserializeLowercaseContentTypeHeader(): void
72+
{
73+
$data = '{ "foo" : "bar" }';
74+
$headers = ['content-type' => ['application/json']];
75+
76+
$result = $this->serializer->deserialize($data, $headers);
77+
78+
$this->assertEquals('bar', $result['foo']);
79+
}
80+
7181
public function testDeserializeWithLegacyContentTypeHeader(): void
7282
{
7383
$data = '{ "foo" : "bar" }';

0 commit comments

Comments
 (0)