From d7a50742f23f7256b132caa39aaa6b55428cd6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Wed, 14 Aug 2024 09:35:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=8F=8A=E7=AB=AF=E5=8F=A3=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/support/ThinkRequest.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin/think-plugs-worker/src/support/ThinkRequest.php b/plugin/think-plugs-worker/src/support/ThinkRequest.php index 40c56b9a2..37a8e4ea1 100644 --- a/plugin/think-plugs-worker/src/support/ThinkRequest.php +++ b/plugin/think-plugs-worker/src/support/ThinkRequest.php @@ -65,10 +65,16 @@ class ThinkRequest extends Request // 请求真实IP $this->realIP = $this->header['x-real-ip'] ?? ($this->header['x-forwarded-for'] ?? $connection->getRemoteIp()); - // 请求地址域名及端口处理 - $this->host = $this->header['x-host'] ?? ($this->header['x-requested-host'] ?? ($this->header['remote-host'] ?? $request->host())); - $port = intval($this->header['x-requested-port'] ?? (strpos($this->host, ':') !== false ? explode(':', $this->host)[1] : $connection->getRemoteIp())); - if (strpos($this->host, ':') !== false && in_array($port, [80, 443])) $this->host = strstr($this->host, ':', true); + // 请求服务器的域名处理 + $this->host = $this->header['x-host'] ?? ($this->header['x-requested-host'] ?? ($this->header['host'] ?? $request->host())); + // 请求服务器的端口处理 + if (!is_numeric($port = $this->header['x-port'] ?? ($this->header['x-requested-port'] ?? ($this->header['port'] ?? null)))) { + $port = strpos($this->host, ':') !== false ? explode(':', $this->host)[1] : $connection->getRemotePort(); + } + // 如果是正常端口,不需要在 host 表示出来 + if (strpos($this->host, ':') !== false && in_array($port, [80, 443])) { + $this->host = strstr($this->host, ':', true); + } // 替换全局变量 $_GET = $request->get();