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

Commit 430a19d

Browse files
committed
Merge branch 'hotfix/169'
Close #169
2 parents da877f1 + 3b9ba35 commit 430a19d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ All notable changes to this project will be documented in this file, in reverse
2929
`SapiStreamEmitter` to implement a check for `isSeekable()` prior to attempts
3030
to rewind; this allows it to work with non-seekable streams such as the
3131
`CallbackStream`.
32+
- [#169](https://github.com/zendframework/zend-diactoros/pull/169) ensures that
33+
response serialization always provides a `\r\n\r\n` sequence following the
34+
headers, even when no message body is present, to ensure it conforms with RFC
35+
7230.
3236

3337
## 1.3.5 - 2016-03-17
3438

src/Response/Serializer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ public static function toString(ResponseInterface $response)
7373
if (! empty($headers)) {
7474
$headers = "\r\n" . $headers;
7575
}
76-
if (! empty($body)) {
77-
$headers .= "\r\n\r\n";
78-
}
76+
77+
$headers .= "\r\n\r\n";
7978

8079
return sprintf(
8180
$format,

test/Response/SerializerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ public function testSerializesBasicResponse()
3131
);
3232
}
3333

34+
public function testSerializesResponseWithoutBodyCorrectly()
35+
{
36+
$response = (new Response())
37+
->withStatus(200)
38+
->withAddedHeader('Content-Type', 'text/plain');
39+
40+
$message = Serializer::toString($response);
41+
$this->assertEquals(
42+
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n",
43+
$message
44+
);
45+
}
46+
3447
public function testSerializesMultipleHeadersCorrectly()
3548
{
3649
$response = (new Response())

0 commit comments

Comments
 (0)