Skip to content

Commit

Permalink
Implement withoutHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 23, 2016
1 parent 95d9b06 commit f6393f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Network/Request.php
Expand Up @@ -1051,14 +1051,14 @@ public function withAddedHeader($name, $value)
/**
* Get a modified request without a provided header.
*
* @param string $name The header name.
* @param string $name The header name to remove.
* @return static
*/
public function withoutHeader($name)
{
$new = clone $this;
$name = $this->normalizeHeaderName($name);
$new->_environment[$name] = $value;
unset($new->_environment[$name]);

return $new;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase/Network/RequestTest.php
Expand Up @@ -1354,6 +1354,28 @@ public function testWithHeader()
$this->assertEquals(['a'], $new->header('Double'), 'headers written in bc way.');
}

/**
* Test removing a header.
*
* @return void
*/
public function testWithoutHeader()
{
$request = new Request(['environment' => [
'HTTP_HOST' => 'localhost',
'CONTENT_TYPE' => 'application/json',
'CONTENT_LENGTH' => 1337,
'HTTP_CONTENT_MD5' => 'abc123',
'HTTP_DOUBLE' => ['a', 'b']
]]);
$new = $request->withoutHeader('Content-Length', 999);
$this->assertNotSame($new, $request);

$this->assertEquals(1337, $request->getHeaderLine('Content-length'), 'old request is unchanged');
$this->assertEquals('', $new->getHeaderLine('Content-length'), 'new request is correct');
$this->assertNull($new->header('Content-Length'));
}

/**
* Test accepts() with and without parameters
*
Expand Down

0 comments on commit f6393f3

Please sign in to comment.