Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge 083343b into 7561382
Browse files Browse the repository at this point in the history
  • Loading branch information
snapshotpl committed Jul 19, 2018
2 parents 7561382 + 083343b commit 8731b51
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,13 @@ public function getUri()
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$normalizedHeader = 'host';
$new = clone $this;
$new->uri = $uri;

if ($preserveHost && $this->hasHeader('Host')) {
$hasHeader = isset($this->headerNames[$normalizedHeader]);

if ($preserveHost && isset($hasHeader)) {
return $new;
}

Expand All @@ -267,18 +270,13 @@ public function withUri(UriInterface $uri, $preserveHost = false)
$host .= ':' . $uri->getPort();
}

$new->headerNames['host'] = 'Host';

// Remove an existing host header if present, regardless of current
// de-normalization of the header name.
// @see https://github.com/zendframework/zend-diactoros/issues/91
foreach (array_keys($new->headers) as $header) {
if (strtolower($header) === 'host') {
unset($new->headers[$header]);
}
if ($hasHeader) {
unset($new->headers[$new->headerNames[$normalizedHeader]]);
}

$new->headers['Host'] = [$host];
$header = 'Host';
$new->headerNames[$normalizedHeader] = $header;
$new->headers[$header] = [$host];

return $new;
}
Expand Down

0 comments on commit 8731b51

Please sign in to comment.