fix: getHeader for Content-Type & Content-Length (#1703)

* fix: Request::getHeader for Content-Type & Content-Length

* fix: get content-type through native api

---------

Co-authored-by: joyqi <joyqi@users.noreply.github.com>
This commit is contained in:
电脑星人 2024-01-13 22:11:38 +08:00 committed by GitHub
parent a30a6c122d
commit 4028d7d160
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -367,10 +367,7 @@ class Request
*/
public function getContentType(): ?string
{
return $this->getServer(
'CONTENT_TYPE',
$this->getServer('HTTP_CONTENT_TYPE')
);
return $this->getHeader('Content-Type');
}
/**
@ -420,8 +417,14 @@ class Request
*/
public function getHeader(string $key, ?string $default = null): ?string
{
$key = 'HTTP_' . strtoupper(str_replace('-', '_', $key));
return $this->getServer($key, $default);
$key = strtoupper(str_replace('-', '_', $key));
// Content-Type 和 Content-Length 这两个 header 还需要从不带 HTTP_ 的 key 尝试获取
if (in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) {
$default = $this->getServer($key, $default);
}
return $this->getServer('HTTP_' . $key, $default);
}
/**