| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
修复在 Swoole 6.2.0 新增 server_addr 字段后,getUriFromGlobals() 解析 host 时 server_addr 覆盖 header['host'] 导致 getUri()->getHost() 返回服务器本地 IP 的问题(Fix #7744),使其行为与 PHP-FPM/nginx 更一致。
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/http-message/src/Server/Request.php | 调整 getUriFromGlobals() 的 host fallback 顺序,避免 Swoole 6.2.0 的 server_addr 覆盖客户端 Host 头 |
| src/http-message/tests/ServerRequestTest.php | 增加两个测试用例覆盖 Swoole 6.2.0 的 server_addr 场景与无 Host 的回退行为 |
src/http-message/src/Server/Request.php:599
} elseif (isset($header['host'])) {
$hasPort = true;
[$host, $port] = self::parseHost($header['host']);
if (isset($port) && $port !== $uri->getDefaultPort()) {
$uri = $uri->withPort($port);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| // 模拟 Swoole 6.2.0 在 $request->server 中设置 server_addr 的场景 | ||
| // header['host'] 应优先于 server_addr |
There was a problem hiding this comment.
New inline comments are written in Chinese, while the rest of the tests in this package use English-only docblocks/identifiers. For consistency and easier collaboration across the project, consider translating these comments to English or removing them if they’re not essential.
| // 模拟 Swoole 6.2.0 在 $request->server 中设置 server_addr 的场景 | |
| // header['host'] 应优先于 server_addr | |
| // Simulate the Swoole 6.2.0 scenario where server_addr is set in $request->server. | |
| // header['host'] should take precedence over server_addr. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fix #7744 #7735
问题
Swoole 6.2.0 在 $swooleRequest->server 中新增了 server_addr 字段(服务器本地 IP)。当前代码中 server_addr 的优先级高于 header['host'],导致 getUri()->getHost() 返回服务器本地 IP(如 127.0.0.1)而非 HTTP Host 请求头中的域名(如 hyperf.example.com)。
修复前优先级:http_host → server_name → server_addr → header['host']
这与 PHP-FPM / nginx 的行为不一致——$_SERVER['HTTP_HOST'] 始终优先于 SERVER_ADDR。
修复
调整优先级为:http_host → header['host'] → server_name → server_addr
变更