Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Fix Request::hasHeader('Host'). Fixed #2
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed May 29, 2016
1 parent 073a8ab commit 9a13b92
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ public function getHeader($name)
return (array) $this->headers[$name];
}

/**
* Checks if a header exists by the given case-insensitive name.
*
* @param string $name Case-insensitive header field name.
*
* @return bool Returns true if any header names match the given header
* name using a case-insensitive string comparison. Returns false if
* no matching header name is found in the message.
*/
public function hasHeader($name)
{
if (strtolower($name) === 'host' && ($this->uri && $this->uri->getHost()))
{
$this->headerNames['host'] = $name;
$this->headers[$name] = array($this->getHostFromUri());
}

return parent::hasHeader($name);
}

/**
* Retrieve the host from the URI instance
*
Expand Down
16 changes: 16 additions & 0 deletions test/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,20 @@ public function testGetHeader()

$this->assertEquals(array('windwalker.io'), $request->getHeader('host'));
}

/**
* Method to test hasHeader().
*
* @return void
*
* @covers Asika\Http\Request::hasHeader
*/
public function testHasHeader()
{
$request = new \Asika\Http\Request('http://example.com/foo', 'GET');

$this->assertTrue($request->hasHeader('host'));
$this->assertTrue($request->hasHeader('Host'));
$this->assertFalse($request->hasHeader('X-Foo'));
}
}

0 comments on commit 9a13b92

Please sign in to comment.