Skip to content

Commit f834027

Browse files
committed
Add support for multi-value response headers with API Gateway v2
1 parent d789c22 commit f834027

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Event/Http/HttpResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function toApiGatewayFormatV2(): array
7272
} else {
7373
// Make sure the values are never arrays
7474
// because API Gateway v2 does not support multi-value headers
75-
$headers[$name] = is_array($values) ? end($values) : $values;
75+
$headers[$name] = is_array($values) ? implode(', ', $values) : $values;
7676
}
7777
}
7878

tests/Event/Http/HttpResponseTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function test headers are capitalized()
5858
], $response->toApiGatewayFormatV2());
5959
}
6060

61-
public function test nested arrays in headers are flattened()
61+
public function test multi value headers()
6262
{
6363
$response = new HttpResponse('', [
6464
'foo' => ['bar', 'baz'],
@@ -76,8 +76,10 @@ public function test nested arrays in headers are flattened()
7676
'cookies' => [],
7777
'isBase64Encoded' => false,
7878
'statusCode' => 200,
79-
// The last value is kept (when multiheaders are not enabled)
80-
'headers' => ['Foo' => 'baz'],
79+
// Headers are joined with a comma
80+
// See https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.2
81+
// API Gateway v2 does not support multi-value headers
82+
'headers' => ['Foo' => 'bar, baz'],
8183
'body' => '',
8284
], $response->toApiGatewayFormatV2());
8385
}

0 commit comments

Comments
 (0)