mirror of
https://github.com/typecho/typecho.git
synced 2025-04-21 02:01:52 +02:00
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:
parent
a30a6c122d
commit
4028d7d160
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user