Skip to content

Commit

Permalink
Merge pull request #1730 from brefphp/multi-value-response-headers-v2
Browse files Browse the repository at this point in the history
Add support for multi-value response headers with API Gateway v2
  • Loading branch information
mnapoli authored Jan 31, 2024
2 parents 44bdff0 + f834027 commit 1fd4a98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit 1fd4a98

Please sign in to comment.