From 60fe987ed889ce4b0d9c1c7a81a4e81153b5ee4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Fri, 24 Jun 2016 16:06:39 +0300 Subject: [PATCH 1/3] 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. --- spec/Builder/ResponseBuilderSpec.php | 13 +++++++++++++ src/Builder/ResponseBuilder.php | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/Builder/ResponseBuilderSpec.php b/spec/Builder/ResponseBuilderSpec.php index 606884a..a21ef1b 100644 --- a/spec/Builder/ResponseBuilderSpec.php +++ b/spec/Builder/ResponseBuilderSpec.php @@ -32,4 +32,17 @@ function it_reads_headers_from_string(ResponseInterface $response) $this->beConstructedWith($response); $this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: text/html\r\n"); } + + /** + * @link https://github.com/php-http/message/issues/41 + */ + function it_not_broke_headers(ResponseInterface $response) + { + $response->withStatus(200, 'OK')->willReturn($response); + $response->withProtocolVersion('1.1')->willReturn($response); + $response->hasHeader('Content-type')->willReturn(false); + $response->withHeader('Content-type', 'application/xml+atom')->willReturn($response); + $this->beConstructedWith($response); + $this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: application/xml+atom\r\n"); + } } diff --git a/src/Builder/ResponseBuilder.php b/src/Builder/ResponseBuilder.php index 0a198f4..e6933a0 100644 --- a/src/Builder/ResponseBuilder.php +++ b/src/Builder/ResponseBuilder.php @@ -135,8 +135,8 @@ public function addHeader($headerLine) sprintf('"%s" is not a valid HTTP header line', $headerLine) ); } - $name = trim(urldecode($parts[0])); - $value = trim(urldecode($parts[1])); + $name = trim($parts[0]); + $value = trim($parts[1]); if ($this->response->hasHeader($name)) { $this->response = $this->response->withAddedHeader($name, $value); } else { From 9c4c1dbde21af4493a51ecc993f2a3b07ad8129c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Fri, 24 Jun 2016 16:09:59 +0300 Subject: [PATCH 2/3] Update CHANGELOG. --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6776f57..ab7a8ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## Unreleased + +### Fixed + +- #41: Response builder broke header value + + ## 1.2.0 - 2016-03-29 ### Added From 96c6b277b2ecdb1be42a6bd165c90184d96c4a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Mon, 27 Jun 2016 10:16:07 +0300 Subject: [PATCH 3/3] Update tests. --- spec/Builder/ResponseBuilderSpec.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/spec/Builder/ResponseBuilderSpec.php b/spec/Builder/ResponseBuilderSpec.php index a21ef1b..c4cc81e 100644 --- a/spec/Builder/ResponseBuilderSpec.php +++ b/spec/Builder/ResponseBuilderSpec.php @@ -23,20 +23,10 @@ function it_reads_headers_from_array(ResponseInterface $response) $this->setHeadersFromArray(['HTTP/1.1 200 OK', 'Content-type: text/html']); } - function it_reads_headers_from_string(ResponseInterface $response) - { - $response->withStatus(200, 'OK')->willReturn($response); - $response->withProtocolVersion('1.1')->willReturn($response); - $response->hasHeader('Content-type')->willReturn(false); - $response->withHeader('Content-type', 'text/html')->willReturn($response); - $this->beConstructedWith($response); - $this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: text/html\r\n"); - } - /** * @link https://github.com/php-http/message/issues/41 */ - function it_not_broke_headers(ResponseInterface $response) + function it_splits_headers_correctly(ResponseInterface $response) { $response->withStatus(200, 'OK')->willReturn($response); $response->withProtocolVersion('1.1')->willReturn($response);