Skip to content

Commit

Permalink
Join multiheader values
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed Nov 12, 2023
1 parent a249ebd commit 9cf9de7
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/web/ResponseBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ public function events(): array

public function afterPrepare(Event $event): void
{
foreach ($this->csvHeaders as $name) {
$this->joinHeaderValues($name, ', ');
}
// API Gateway v2 does not support multi-header values
$this->joinMultiValueHeaders();

if ($event->sender->stream) {
if ($this->owner->stream) {
$this->serveBinaryFromS3();
}
}
Expand Down Expand Up @@ -80,19 +79,21 @@ protected function serveBinaryFromS3(): void
$this->owner->redirect($url);
}

protected function joinHeaderValues($name, string $glue): ?string
protected function joinMultiValueHeaders(string $glue = ','): void
{
$headers = $this->owner->getHeaders();
Collection::make($this->owner->getHeaders())
->each(function(array $values, string $name) use ($glue) {
$this->joinHeaderValues($name, $values, $glue);
});
}

$value = Collection::make($headers->get($name, null, false))
protected function joinHeaderValues(string $name, array $values, string $glue): ?string
{
$value = Collection::make($values)
->filter()
->join($glue);

if (!$value) {
return null;
}

$headers->set($name, $value);
$this->owner->getHeaders()->set($name, $value);

return $value;
}
Expand Down

0 comments on commit 9cf9de7

Please sign in to comment.