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

Commit 9580991

Browse files
committed
psr-7 attempt to set the Host header during construction
fixes: #172
1 parent b4e7758 commit 9580991

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/RequestTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ private function initialize($uri = null, $method = null, $body = 'php://memory',
6969
list($this->headerNames, $headers) = $this->filterHeaders($headers);
7070
$this->assertHeaders($headers);
7171
$this->headers = $headers;
72+
73+
// per PSR-7: attempt to set the Host header from a provided URI if no
74+
// Host header is provided
75+
if (! $this->hasHeader('Host') && $this->uri->getHost()) {
76+
$this->headerNames['host'] = 'Host';
77+
$this->headers['host'] = [$this->getHostFromUri()];
78+
}
7279
}
7380

7481
/**

0 commit comments

Comments
 (0)