Skip to content
Permalink
Browse files

Implement withoutHeader

  • Loading branch information...
markstory committed Sep 23, 2016
1 parent 95d9b06 commit f6393f3468229a4d819adf07e51a3671dca178cb
Showing with 24 additions and 2 deletions.
  1. +2 −2 src/Network/Request.php
  2. +22 −0 tests/TestCase/Network/RequestTest.php
@@ -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;
}
@@ -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
*

0 comments on commit f6393f3

Please sign in to comment.
You can’t perform that action at this time.