Skip to content

Commit 60fe987

Browse files
committed
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 60fe987

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

spec/Builder/ResponseBuilderSpec.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,17 @@ function it_reads_headers_from_string(ResponseInterface $response)
3232
$this->beConstructedWith($response);
3333
$this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: text/html\r\n");
3434
}
35+
36+
/**
37+
* @link https://github.com/php-http/message/issues/41
38+
*/
39+
function it_not_broke_headers(ResponseInterface $response)
40+
{
41+
$response->withStatus(200, 'OK')->willReturn($response);
42+
$response->withProtocolVersion('1.1')->willReturn($response);
43+
$response->hasHeader('Content-type')->willReturn(false);
44+
$response->withHeader('Content-type', 'application/xml+atom')->willReturn($response);
45+
$this->beConstructedWith($response);
46+
$this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: application/xml+atom\r\n");
47+
}
3548
}

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)