Skip to content

Commit 15c0be7

Browse files
mekrasdbu
authored andcommitted
Fix #41: Response builder broke header value (#42)
Fix #41: Response builder broke header value As specified at [RFC7230](https://tools.ietf.org/html/rfc7230#section-3.2.4), headers charset should be limited to US-ASCII.
1 parent c8fadec commit 15c0be7

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Fixed
6+
7+
- #41: Response builder broke header value
8+
9+
310
## 1.2.0 - 2016-03-29
411

512
### Added

spec/Builder/ResponseBuilderSpec.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ function it_reads_headers_from_array(ResponseInterface $response)
2323
$this->setHeadersFromArray(['HTTP/1.1 200 OK', 'Content-type: text/html']);
2424
}
2525

26-
function it_reads_headers_from_string(ResponseInterface $response)
26+
/**
27+
* @link https://github.com/php-http/message/issues/41
28+
*/
29+
function it_splits_headers_correctly(ResponseInterface $response)
2730
{
2831
$response->withStatus(200, 'OK')->willReturn($response);
2932
$response->withProtocolVersion('1.1')->willReturn($response);
3033
$response->hasHeader('Content-type')->willReturn(false);
31-
$response->withHeader('Content-type', 'text/html')->willReturn($response);
34+
$response->withHeader('Content-type', 'application/xml+atom')->willReturn($response);
3235
$this->beConstructedWith($response);
33-
$this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: text/html\r\n");
36+
$this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: application/xml+atom\r\n");
3437
}
3538
}

src/Builder/ResponseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public function addHeader($headerLine)
135135
sprintf('"%s" is not a valid HTTP header line', $headerLine)
136136
);
137137
}
138-
$name = trim(urldecode($parts[0]));
139-
$value = trim(urldecode($parts[1]));
138+
$name = trim($parts[0]);
139+
$value = trim($parts[1]);
140140
if ($this->response->hasHeader($name)) {
141141
$this->response = $this->response->withAddedHeader($name, $value);
142142
} else {

0 commit comments

Comments
 (0)