Skip to content

Commit

Permalink
Add simple body to upgrade error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Oct 22, 2023
1 parent 928e54b commit f5bb36b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Internal/UpgradeErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Http\HttpStatus;
use Amp\Http\Server\ErrorHandler;
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
Expand All @@ -16,6 +17,10 @@ final class UpgradeErrorHandler implements ErrorHandler

public function handleError(int $status, ?string $reason = null, ?Request $request = null): Response
{
return new Response($status, ['connection' => 'close']);
return new Response(
status: $status,
headers: ['content-type' => 'text/plain; charset=utf-8', 'connection' => 'close'],
body: \sprintf('%d %s', $status, $reason ?? HttpStatus::getReason($status)),
);
}
}

0 comments on commit f5bb36b

Please sign in to comment.