Skip to content

Commit

Permalink
Headers are now correctly overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
esbenp committed Jun 26, 2015
1 parent 6df875e commit c997805
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function singleRequest($method, $uri, array $data = [], array $headers =
// after we've completed our internal request.
$currentRequest = $this->request->instance()->duplicate();

$headers = $this->overrideHeaders($currentRequest->headers->all(), $headers);
$headers = $this->overrideHeaders($currentRequest->server->getHeaders(), $headers);

if ($this->disableMiddleware) {
$this->app->instance('middleware.disable', true);
Expand Down Expand Up @@ -145,6 +145,7 @@ public function singleRequest($method, $uri, array $data = [], array $headers =

private function overrideHeaders(array $default, array $headers)
{
$headers = $this->transformHeadersToUppercaseUnderscoreType($headers);
return array_merge($default, $headers);
}

Expand Down Expand Up @@ -192,6 +193,19 @@ private function createRequest($method, $uri, array $data = [], array $headers =
return $this->request->create($uri, $method, $data, [], [], $server, $content);
}

private function transformHeadersToUppercaseUnderscoreType($headers)
{
$transformed = [];

foreach($headers as $headerType => $headerValue) {
$headerType = strtoupper(str_replace('-', '_', $headerType));

$transformed[$headerType] = $headerValue;
}

return $transformed;
}

/**
* https://github.com/symfony/symfony/issues/5074
*
Expand All @@ -203,7 +217,7 @@ private function transformHeadersToServerVariables($headers)
$server = [];

foreach($headers as $headerType => $headerValue){
$headerType = 'HTTP_' . strtoupper(str_replace('-', '_', $headerType));
$headerType = 'HTTP_' . $headerType;

$server[$headerType] = $headerValue;
}
Expand Down

0 comments on commit c997805

Please sign in to comment.