From c9909e322bb43167d7caeee76e4d574f0024cf40 Mon Sep 17 00:00:00 2001 From: "Mr.L" Date: Mon, 18 Nov 2024 15:40:56 +0800 Subject: [PATCH] Fixed Url using full path plus query parameter Fix the url to include the full path and parameters so that the middleware can use getUri to get the parameters. --- src/PsrRequestFactory.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PsrRequestFactory.php b/src/PsrRequestFactory.php index 993513a..38d24dd 100644 --- a/src/PsrRequestFactory.php +++ b/src/PsrRequestFactory.php @@ -23,9 +23,18 @@ public function create(SwooleRequest $swooleRequest): ServerRequestInterface { $server = array_change_key_case($swooleRequest->server ?? [], CASE_UPPER); + list($scheme, $protocolVersion) = explode('/', $server['SERVER_PROTOCOL']); + $scheme = strtolower($scheme); + $host = $server["SERVER_HOST"] ?? '0.0.0.0'; + $port = $server["SERVER_PORT"] ?? ''; + $port = in_array($port, [80, 443]) ? '' : ":{$port}"; + $requestUri = $server['REQUEST_URI'] ?? ''; + $queryString = $server['QUERY_STRING'] ?? ''; + $uri = $scheme . '://' . $host . $port . $requestUri . ($queryString ? "?{$queryString}" : ''); + $request = $this->serverRequestFactory->createServerRequest( $server['REQUEST_METHOD'] ?? 'GET', - $server['REQUEST_URI'] ?? '', + $uri, $server );