mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Revert "Fix #19290: Fix Request::getHostInfo() doesn’t return the port if a Host header is used"
This reverts commit 8046d3a50f207e1033e1b23ff571da5bced0c822.
This commit is contained in:
@ -13,7 +13,6 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #19270: Replace deprecated `scss` converter in `yii\web\AssetConverter::$commands` (WinterSilence)
|
- Enh #19270: Replace deprecated `scss` converter in `yii\web\AssetConverter::$commands` (WinterSilence)
|
||||||
- Enh #19254: Support specifying custom characters for `yii.validation.trim()` and replace deprecated `jQuery.trim()` (WinterSilence)
|
- Enh #19254: Support specifying custom characters for `yii.validation.trim()` and replace deprecated `jQuery.trim()` (WinterSilence)
|
||||||
- Bug #19291: Reset errors and validators in `yii\base\Model::__clone()` (WinterSilence)
|
- Bug #19291: Reset errors and validators in `yii\base\Model::__clone()` (WinterSilence)
|
||||||
- Bug #19290: Fix `Request::getHostInfo()` doesn’t return the port if a Host header is used (lesha724)
|
|
||||||
- Enh #19295: Added alias `text/rtf` for mime-type `application/rtf` (lesha724)
|
- Enh #19295: Added alias `text/rtf` for mime-type `application/rtf` (lesha724)
|
||||||
- Enh #19308: Add `yii\web\UploadedFile::$fullPath` represents 'full_path' key added in PHP 8.1 (WinterSilence)
|
- Enh #19308: Add `yii\web\UploadedFile::$fullPath` represents 'full_path' key added in PHP 8.1 (WinterSilence)
|
||||||
- Bug #19303: Fix serialization in `yii\caching\Dependency::generateReusableHash()` (WinterSilence)
|
- Bug #19303: Fix serialization in `yii\caching\Dependency::generateReusableHash()` (WinterSilence)
|
||||||
|
|||||||
@ -764,23 +764,16 @@ class Request extends \yii\base\Request
|
|||||||
$this->_hostInfo = $http . '://' . trim(explode(',', $this->headers->get('X-Forwarded-Host'))[0]);
|
$this->_hostInfo = $http . '://' . trim(explode(',', $this->headers->get('X-Forwarded-Host'))[0]);
|
||||||
} elseif ($this->headers->has('X-Original-Host')) {
|
} elseif ($this->headers->has('X-Original-Host')) {
|
||||||
$this->_hostInfo = $http . '://' . trim(explode(',', $this->headers->get('X-Original-Host'))[0]);
|
$this->_hostInfo = $http . '://' . trim(explode(',', $this->headers->get('X-Original-Host'))[0]);
|
||||||
} else {
|
} elseif ($this->headers->has('Host')) {
|
||||||
if ($this->headers->has('Host')) {
|
|
||||||
$this->_hostInfo = $http . '://' . $this->headers->get('Host');
|
$this->_hostInfo = $http . '://' . $this->headers->get('Host');
|
||||||
} elseif (filter_has_var(INPUT_SERVER, 'SERVER_NAME')) {
|
|
||||||
$this->_hostInfo = $http . '://' . filter_input(INPUT_SERVER, 'SERVER_NAME');
|
|
||||||
} elseif (isset($_SERVER['SERVER_NAME'])) {
|
} elseif (isset($_SERVER['SERVER_NAME'])) {
|
||||||
$this->_hostInfo = $http . '://' . $_SERVER['SERVER_NAME'];
|
$this->_hostInfo = $http . '://' . $_SERVER['SERVER_NAME'];
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_hostInfo !== null && !preg_match('/:\d+$/', $this->_hostInfo)) {
|
|
||||||
$port = $secure ? $this->getSecurePort() : $this->getPort();
|
$port = $secure ? $this->getSecurePort() : $this->getPort();
|
||||||
if (($port !== 80 && !$secure) || ($port !== 443 && $secure)) {
|
if (($port !== 80 && !$secure) || ($port !== 443 && $secure)) {
|
||||||
$this->_hostInfo .= ':' . $port;
|
$this->_hostInfo .= ':' . $port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_hostInfo;
|
return $this->_hostInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -286,48 +286,6 @@ class RequestTest extends TestCase
|
|||||||
'example1.com',
|
'example1.com',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
// HTTP header missing with port 80
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'HTTP_HOST' => 'example1.com',
|
|
||||||
'SERVER_PORT' => 80,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://example1.com',
|
|
||||||
'example1.com',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// normal with nonstandart port 8080
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'HTTP_HOST' => 'example1.com',
|
|
||||||
'SERVER_PORT' => 8080,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://example1.com:8080',
|
|
||||||
'example1.com',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'HTTP_HOST' => 'example1.com:8081',
|
|
||||||
'SERVER_PORT' => 8080,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://example1.com:8081',
|
|
||||||
'example1.com',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'HTTP_HOST' => 'example1.com:8080',
|
|
||||||
'SERVER_PORT' => 8080,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://example1.com:8080',
|
|
||||||
'example1.com',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// HTTP header missing
|
// HTTP header missing
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
@ -338,28 +296,6 @@ class RequestTest extends TestCase
|
|||||||
'example2.com',
|
'example2.com',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
// HTTP header missing with nonstandart port 8080
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'SERVER_NAME' => 'example1.com',
|
|
||||||
'SERVER_PORT' => 8080,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://example1.com:8080',
|
|
||||||
'example1.com',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// HTTP header missing with port 80
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'SERVER_NAME' => 'example1.com',
|
|
||||||
'SERVER_PORT' => 80,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://example1.com',
|
|
||||||
'example1.com',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
// forwarded from untrusted server
|
// forwarded from untrusted server
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user