From c3e56186e25e31844bf427d13397d31cae9598aa Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Wed, 6 Mar 2024 17:40:18 +0200 Subject: [PATCH] Remove unused code --- composer.json | 5 ++--- src/HttpWorker.php | 56 ++++------------------------------------------ 2 files changed, 6 insertions(+), 55 deletions(-) diff --git a/composer.json b/composer.json index e170999..fa0b40f 100644 --- a/composer.json +++ b/composer.json @@ -42,14 +42,13 @@ "psr/http-factory": "^1.0.1", "psr/http-message": "^1.0.1 || ^2.0", "spiral/roadrunner": "^2023.3", - "spiral/roadrunner-worker": "^3.3.0" + "spiral/roadrunner-worker": "^3.3.0", + "roadrunner-php/roadrunner-api-dto": "^1.5" }, "require-dev": { - "buggregator/trap": "^1.0", "jetbrains/phpstorm-attributes": "^1.0", "nyholm/psr7": "^1.3", "phpunit/phpunit": "^10.0", - "roadrunner-php/roadrunner-api-dto": "^1.4", "symfony/process": "^6.2", "symfony/var-dumper": "^6.3", "vimeo/psalm": "^5.9" diff --git a/src/HttpWorker.php b/src/HttpWorker.php index 6626f6f..fda20ae 100644 --- a/src/HttpWorker.php +++ b/src/HttpWorker.php @@ -8,7 +8,6 @@ use RoadRunner\HTTP\DTO\V1BETA1\FileUpload; use RoadRunner\HTTP\DTO\V1BETA1\HeaderValue; use RoadRunner\HTTP\DTO\V1BETA1\Request as RequestProto; -use Spiral\RoadRunner\Encoding; use Spiral\RoadRunner\Http\Exception\StreamStoppedException; use Spiral\RoadRunner\Message\Command\StreamStop; use Spiral\RoadRunner\Payload; @@ -21,19 +20,6 @@ * @psalm-import-type UploadedFilesList from Request * @psalm-import-type CookiesList from Request * - * @psalm-type RequestContext = array{ - * remoteAddr: non-empty-string, - * protocol: non-empty-string, - * method: non-empty-string, - * uri: string, - * attributes: AttributesList, - * headers: HeadersList, - * cookies: CookiesList, - * uploads: UploadedFilesList|null, - * rawQuery: string, - * parsed: bool - * } - * * @see Request */ class HttpWorker implements HttpWorkerInterface @@ -48,9 +34,6 @@ public function getWorker(): WorkerInterface return $this->worker; } - /** - * @throws \JsonException - */ public function waitRequest(): ?Request { $payload = $this->worker->waitPayload(); @@ -60,17 +43,10 @@ public function waitRequest(): ?Request return null; } - if ($payload->encoding === Encoding::Protobuf) { - $message = new RequestProto(); - $message->mergeFromString($payload->body); + $message = new RequestProto(); + $message->mergeFromString($payload->body); - return $this->requestFromProto($message); - } - - /** @var RequestContext $context */ - $context = \json_decode($payload->header, true, 512, \JSON_THROW_ON_ERROR); - - return $this->arrayToRequest($payload->body, $context); + return $this->requestFromProto($message); } /** @@ -142,29 +118,6 @@ private function respondStream(int $status, Generator $body, array $headers = [] } while (true); } - /** - * @param RequestContext $context - */ - private function arrayToRequest(string $body, array $context): Request - { - \parse_str($context['rawQuery'], $query); - return new Request( - remoteAddr: $context['remoteAddr'], - protocol: $context['protocol'], - method: $context['method'], - uri: $context['uri'], - headers: $this->filterHeaders((array)($context['headers'] ?? [])), - cookies: (array)($context['cookies'] ?? []), - uploads: (array)($context['uploads'] ?? []), - attributes: [ - Request::PARSED_BODY_ATTRIBUTE_NAME => $context['parsed'], - ] + (array)($context['attributes'] ?? []), - query: $query, - body: $body, - parsed: $context['parsed'], - ); - } - private function requestFromProto(RequestProto $message): Request { $headers = $this->headerValueToArray($message->getHeader()); @@ -200,8 +153,7 @@ private function requestFromProto(RequestProto $message): Request Request::PARSED_BODY_ATTRIBUTE_NAME => $message->getParsed(), ] + \iterator_to_array($message->getAttributes()), query: $query, - // todo rawBody? - body: $message->getBody(), + body: $message->getRawQuery(), parsed: $message->getParsed(), ); }