Skip to content

Commit 89f6c49

Browse files
committed
Add Message::removeHeadersByNames method
1 parent 9f2c571 commit 89f6c49

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/Message.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,21 @@ protected function removeHeaders() : static
243243
return $this;
244244
}
245245

246+
/**
247+
* Remove headers by names.
248+
*
249+
* @param array<string> $names
250+
*
251+
* @return static
252+
*/
253+
protected function removeHeadersByNames(array $names) : static
254+
{
255+
foreach ($names as $name) {
256+
$this->removeHeader($name);
257+
}
258+
return $this;
259+
}
260+
246261
/**
247262
* Say if the Message has a Cookie.
248263
*

tests/MessageMock.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function removeHeaders() : static
4444
return parent::removeHeaders();
4545
}
4646

47+
public function removeHeadersByNames(array $names) : static
48+
{
49+
return parent::removeHeadersByNames($names);
50+
}
51+
4752
public function setBody(?string $body) : static
4853
{
4954
return parent::setBody($body);

tests/MessageTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ public function testHeaders() : void
9797
);
9898
$this->message->removeHeaders();
9999
self::assertSame([], $this->message->getHeaders());
100+
$this->message->setHeaders([
101+
'content-type' => 'application/json',
102+
'allow' => '*',
103+
]);
104+
self::assertSame(
105+
[
106+
'content-type' => 'application/json',
107+
'allow' => '*',
108+
],
109+
$this->message->getHeaders()
110+
);
111+
$this->message->removeHeadersByNames(['content-type']);
112+
self::assertSame(
113+
[
114+
'allow' => '*',
115+
],
116+
$this->message->getHeaders()
117+
);
100118
}
101119

102120
public function testHeaderLine() : void

0 commit comments

Comments
 (0)