-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues like walkor/workerman#403
- Loading branch information
Showing
3 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Manyou\WorkermanSymfonyRuntime; | ||
|
||
use Chubbyphp\WorkermanRequestHandler\OnMessageInterface; | ||
use Chubbyphp\WorkermanRequestHandler\PsrRequestFactoryInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Workerman\Connection\TcpConnection as WorkermanTcpConnection; | ||
use Workerman\Protocols\Http\Request as WorkermanRequest; | ||
use Workerman\Protocols\Http\Response as WorkermanResponse; | ||
|
||
use function explode; | ||
use function in_array; | ||
use function strtolower; | ||
|
||
final class OnMessage implements OnMessageInterface | ||
{ | ||
public function __construct( | ||
private PsrRequestFactoryInterface $psrRequestFactory, | ||
private RequestHandlerInterface $requestHander, | ||
) { | ||
} | ||
|
||
public function __invoke(WorkermanTcpConnection $workermanTcpConnection, WorkermanRequest $workermanRequest): void | ||
{ | ||
$response = $this->requestHander->handle( | ||
$this->psrRequestFactory->create($workermanTcpConnection, $workermanRequest), | ||
); | ||
|
||
$workermanTcpConnection->send( | ||
(new WorkermanResponse()) | ||
->withStatus($response->getStatusCode(), $response->getReasonPhrase()) | ||
->withHeaders($response->getHeaders()) | ||
->withBody((string) $response->getBody()), | ||
); | ||
|
||
$keepAlive = in_array('keep-alive', explode(',', strtolower($workermanRequest->header('connection', 'close'))), true); | ||
if (! $keepAlive) { | ||
$workermanTcpConnection->close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters