Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit d6e21b8

Browse files
committed
Merge branch 'hotfix/101' into develop
Forward port #101
2 parents 64cdc57 + a811f4e commit d6e21b8

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ All notable changes to this project will be documented in this file, in reverse
3636

3737
### Fixed
3838

39-
- Nothing.
39+
- [#101](https://github.com/zendframework/zend-diactoros/pull/101) fixes the
40+
`withHeader()` implementation to ensure that if the header existed previously
41+
but using a different casing strategy, the previous version will be removed
42+
in the cloned instance.
4043

4144
## 1.2.0 - 2015-11-24
4245

src/MessageTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ public function withHeader($header, $value)
204204
$normalized = strtolower($header);
205205

206206
$new = clone $this;
207+
if ($new->hasHeader($header)) {
208+
unset($new->headers[$new->headerNames[$normalized]]);
209+
}
207210
$new->headerNames[$normalized] = $header;
208211
$new->headers[$header] = $value;
209212

test/MessageTraitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ public function testWithHeaderRaisesExceptionForInvalidValueType($value)
175175
$message = $this->message->withHeader('X-Foo', $value);
176176
}
177177

178+
public function testWithHeaderReplacesDifferentCapitalization()
179+
{
180+
$this->message = $this->message->withHeader('X-Foo', ['foo']);
181+
$new = $this->message->withHeader('X-foo', ['bar']);
182+
$this->assertEquals(['bar'], $new->getHeader('x-foo'));
183+
$this->assertEquals(['X-foo' => ['bar']], $new->getHeaders());
184+
}
185+
178186
/**
179187
* @dataProvider invalidGeneralHeaderValues
180188
*/

0 commit comments

Comments
 (0)