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

Commit a75dc67

Browse files
committed
Fix reponse serialization if response body is empty.
1 parent 452b01b commit a75dc67

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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)