Skip to content

Commit 27d37f7

Browse files
committed
Response: added deleteHeader(), to be consistent with deleteCookie()
1 parent b847c4e commit 27d37f7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Http/Response.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ public function addHeader(string $name, string $value)
124124
}
125125

126126

127+
/**
128+
* @return static
129+
* @throws Nette\InvalidStateException if HTTP headers have been sent
130+
*/
131+
public function deleteHeader(string $name)
132+
{
133+
self::checkHeaders();
134+
header_remove($name);
135+
return $this;
136+
}
137+
138+
127139
/**
128140
* Sends a Content-type HTTP header.
129141
* @return static

tests/Http/Response.headers.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ Assert::same('one', $response->getHeader('APPEND'));
3636
$headers = $response->getHeaders();
3737
Assert::contains('two', $headers['replace']);
3838
Assert::contains('two', $headers['append']);
39+
40+
41+
$response->deleteHeader('append');
42+
$headers = $response->getHeaders();
43+
Assert::contains('two', $headers['replace']);
44+
Assert::false(isset($headers['append']));

0 commit comments

Comments
 (0)