Skip to content

Commit 76fca0e

Browse files
jimktrainsrenatomefi
authored andcommitted
Issue php-vcr#213. Don't set Host header in setUrl if already set.
1 parent 6eff556 commit 76fca0e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/VCR/Request.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ public static function fromArray(array $request)
132132
public function setUrl($url)
133133
{
134134
$this->url = $url;
135-
$this->setHeader('Host', $this->getHost());
135+
if (! array_key_exists('Host', $this->headers)) {
136+
$this->setHeader('Host', $this->getHost());
137+
}
136138
}
137139

138140
/**

tests/VCR/RequestTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,22 @@ public function testGetHostReturnsBothHostAndPort()
216216
$this->assertEquals('example.com:5000', $request->getHost());
217217
}
218218

219+
public function testDoNotOverwriteHostHeader()
220+
{
221+
$this->request = new Request(
222+
'GET',
223+
'http://example.com',
224+
array('User-Agent' => 'Unit-Test', 'Host' => 'www.example.com'));
225+
226+
$this->assertEquals(
227+
array(
228+
'User-Agent' => 'Unit-Test',
229+
'Host' => 'www.example.com'
230+
),
231+
$this->request->getHeaders()
232+
);
233+
}
234+
219235
public function testCurlCustomRequestOverridesMethod()
220236
{
221237
$postRequest = new Request('POST', 'http://example.com');

0 commit comments

Comments
 (0)