From 25803e38147a9ccb9a3a462ea433a080b30c6144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 30 Aug 2021 15:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-server/Message/Uri.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/http-server/Message/Uri.php b/http-server/Message/Uri.php index 760cd24d..d2372059 100644 --- a/http-server/Message/Uri.php +++ b/http-server/Message/Uri.php @@ -205,11 +205,15 @@ class Uri implements UriInterface */ public function __toString(): string { - if (empty($this->query) && empty($this->fragment)) { - return sprintf('%s://%s:%d%s', $this->scheme, $this->host, $this->port, $this->path); + $domain = sprintf('%s://%s', $this->scheme, $this->host); + if (!in_array($this->port, [80, 443])) { + $domain .= ':' . $this->port; } - return sprintf('%s://%s:%d%s?%s#%s', $this->scheme, $this->host, $this->port, - $this->path, $this->query, $this->fragment); + if (empty($this->query) && empty($this->fragment)) { + return $domain . '/' . $this->path; + } + return sprintf('%s?%s#%s', $domain . '/' . $this->path, + $this->query, $this->fragment); }