Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multi-value response headers with API Gateway v2 #1730

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Event/Http/HttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function toApiGatewayFormatV2(): array
} else {
// Make sure the values are never arrays
// because API Gateway v2 does not support multi-value headers
$headers[$name] = is_array($values) ? end($values) : $values;
$headers[$name] = is_array($values) ? implode(', ', $values) : $values;
}
}

Expand Down
8 changes: 5 additions & 3 deletions tests/Event/Http/HttpResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function test headers are capitalized()
], $response->toApiGatewayFormatV2());
}

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