Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Mar 6, 2024
1 parent f185ea0 commit c3e5618
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 55 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
56 changes: 4 additions & 52 deletions src/HttpWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -48,9 +34,6 @@ public function getWorker(): WorkerInterface
return $this->worker;
}

/**
* @throws \JsonException
*/
public function waitRequest(): ?Request
{
$payload = $this->worker->waitPayload();
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(),
);
}
Expand Down

0 comments on commit c3e5618

Please sign in to comment.