Skip to content

Commit

Permalink
fix: 优化代理域名及端口读取
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujingli committed Aug 14, 2024
1 parent 21aad56 commit d7a5074
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions plugin/think-plugs-worker/src/support/ThinkRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ public function withWorkerRequest(TcpConnection $connection, WorkerRequest $requ
// 请求真实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();
Expand Down

0 comments on commit d7a5074

Please sign in to comment.