Skip to content

Commit

Permalink
Application: Prevent content-type header to be sent multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix Šulc committed Apr 16, 2019
1 parent d3c4ceb commit 763867f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
class Application implements IApplication
{

private const UNIQUE_HEADERS = [
'content-type',
];

/** @var IDispatcher */
private $dispatcher;

Expand Down Expand Up @@ -41,8 +45,9 @@ public function runWith(ApiRequest $request): void
header($httpHeader, true, $response->getStatusCode());

foreach ($response->getHeaders() as $name => $values) {
$replace = in_array(strtolower($name), self::UNIQUE_HEADERS, true) ? true : false;
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
header(sprintf('%s: %s', $name, $value), $replace);
}
}

Expand Down

0 comments on commit 763867f

Please sign in to comment.