From af0f5abb505991e5502e0193c2be8f1d0dee8625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Sun, 23 Apr 2023 14:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Constrict/Uri.php | 19 ------------------- src/Server.php | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Constrict/Uri.php b/src/Constrict/Uri.php index 25ee1bd..5c6dc4f 100644 --- a/src/Constrict/Uri.php +++ b/src/Constrict/Uri.php @@ -387,23 +387,4 @@ class Uri implements UriInterface return $this->scheme . '://x.x.x.x:' . $this->port . '/' . $this->path . '?' . $this->queryString; } - - /** - * @param \Swoole\Http\Request $request - * @return UriInterface - */ - public static function parse(\Swoole\Http\Request $request): UriInterface - { - $uri = new static(); - $uri->queryString = $request->server['query_string'] ?? ''; - $uri->path = $request->server['path_info']; - $uri->port = $request->server['server_port']; - if (isset($request->server['https']) && $request->server['https'] !== 'off') { - $uri->scheme = 'https'; - } else { - $uri->scheme = 'http'; - } - return $uri; - } - } diff --git a/src/Server.php b/src/Server.php index e3623fe..2ed70fd 100644 --- a/src/Server.php +++ b/src/Server.php @@ -15,6 +15,7 @@ use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\UriInterface; use Swoole\Http\Request; use Kiri\Di\Inject\Service; use Swoole\Http\Response; @@ -120,7 +121,7 @@ class Server implements OnRequestInterface $PsrResponse->withContentType($this->response->contentType); $serverRequest = (new ConstrictRequest())->withDataHeaders($request->getData()) - ->withUri(Uri::parse($request)) + ->withUri(static::parse($request)) ->withProtocolVersion($request->server['server_protocol']) ->withCookieParams($request->cookie ?? []) ->withQueryParams($request->get ?? []) @@ -133,4 +134,27 @@ class Server implements OnRequestInterface } + + + + /** + * @param Request $request + * @return UriInterface + */ + public static function parse(Request $request): UriInterface + { + $uri = new Uri(); + $uri->withQuery($request->server['query_string'] ?? '') + ->withPath($request->server['path_info']) + ->withPort($request->server['server_port']); + if (isset($request->server['https']) && $request->server['https'] !== 'off') { + $uri->withScheme('https'); + } else { + $uri->withScheme('http'); + } + return $uri; + } + + + }