Skip to content

Commit

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


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

protected function createInitialRequest(): ServerRequestInterface protected function createInitialRequest(): ServerRequestInterface
{ {
return Psr7ServerRequestFactory::fromGlobal(); return Psr7ServerRequestFactory::fromGlobal();
Expand Down Expand Up @@ -52,8 +56,9 @@ protected function sendHeader(string $name, array $values): void
$name = str_replace('-', ' ', $name); $name = str_replace('-', ' ', $name);
$name = ucwords($name); $name = ucwords($name);
$name = str_replace(' ', '-', $name); $name = str_replace(' ', '-', $name);
$replace = in_array(strtolower($name), self::UNIQUE_HEADERS, true) ? true : false;
foreach ($values as $value) { foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false); header(sprintf('%s: %s', $name, $value), $replace);
} }
} }


Expand Down

0 comments on commit a7e81c9

Please sign in to comment.