Skip to content

Fix #41: Response builder broke header value #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## Unreleased

### Fixed

- #41: Response builder broke header value


## 1.2.0 - 2016-03-29

### Added
Expand Down
9 changes: 6 additions & 3 deletions spec/Builder/ResponseBuilderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ 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)
/**
* @link https://github.com/php-http/message/issues/41
*/
function it_splits_headers_correctly(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);
$response->withHeader('Content-type', 'application/xml+atom')->willReturn($response);
$this->beConstructedWith($response);
$this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: text/html\r\n");
$this->setHeadersFromString("HTTP/1.1 200 OK\r\nContent-type: application/xml+atom\r\n");
}
}
4 changes: 2 additions & 2 deletions src/Builder/ResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the urldecode was in there from the beginning. is something else doing that decoding in reality? is your test failing if you keep the urldecode here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the urldecode was in there from the beginning. is something else doing that decoding in reality?

See comment for 60fe987

is your test failing if you keep the urldecode here?

Yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me the urldecode is not necessary, only ascii characters are allowed.

if ($this->response->hasHeader($name)) {
$this->response = $this->response->withAddedHeader($name, $value);
} else {
Expand Down