Skip to content

Commit 2dda18c

Browse files
authored
Merge pull request #205 from clue-labs/reasons
Refactor to use HTTP response reason phrases from response object
2 parents 0609f8b + bbf48c3 commit 2dda18c

File tree

3 files changed

+10
-81
lines changed

3 files changed

+10
-81
lines changed

src/ResponseCodes.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/Server.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,19 +275,22 @@ function ($error) use ($that, $conn, $request) {
275275
/** @internal */
276276
public function writeError(ConnectionInterface $conn, $code, ServerRequestInterface $request = null)
277277
{
278-
$message = 'Error ' . $code;
279-
if (isset(ResponseCodes::$statusTexts[$code])) {
280-
$message .= ': ' . ResponseCodes::$statusTexts[$code];
281-
}
282-
283278
$response = new Response(
284279
$code,
285280
array(
286281
'Content-Type' => 'text/plain'
287282
),
288-
$message
283+
'Error ' . $code
289284
);
290285

286+
// append reason phrase to response body if known
287+
$reason = $response->getReasonPhrase();
288+
if ($reason !== '') {
289+
$body = $response->getBody();
290+
$body->seek(0, SEEK_END);
291+
$body->write(': ' . $reason);
292+
}
293+
291294
if ($request === null) {
292295
$request = new ServerRequest('GET', '/', array(), null, '1.1');
293296
}

tests/ServerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ function ($data) use (&$buffer) {
12171217

12181218
$this->assertContains("HTTP/1.1 505 HTTP Version not supported\r\n", $buffer);
12191219
$this->assertContains("\r\n\r\n", $buffer);
1220-
$this->assertContains("Error 505: HTTP Version Not Supported", $buffer);
1220+
$this->assertContains("Error 505: HTTP Version not supported", $buffer);
12211221
}
12221222

12231223
public function testRequestOverflowWillEmitErrorAndSendErrorResponse()

0 commit comments

Comments
 (0)