fix the source to get content type (#1622)

This commit is contained in:
joyqi 2023-09-22 10:50:39 +08:00 committed by GitHub
parent 9910a9cddc
commit 91ae56484d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -351,6 +351,19 @@ class Request
return ($this->pathInfo = '/' . ltrim(urldecode($pathInfo), '/'));
}
/**
* 获取请求的内容类型
*
* @return string|null
*/
public function getContentType(): ?string
{
return $this->getServer(
'CONTENT_TYPE',
$this->getServer('HTTP_CONTENT_TYPE')
);
}
/**
* 获取环境变量
*
@ -492,7 +505,10 @@ class Request
*/
public function isJson(): bool
{
return !!preg_match("/^\s*application\/json(;|$)/i", $this->getHeader('Content-Type', ''));
return !!preg_match(
"/^\s*application\/json(;|$)/i",
$this->getContentType() ?? ''
);
}
/**

View File

@ -213,6 +213,16 @@ class Request
return $this->request->makeUriByRequest($parameter);
}
/**
* 获取请求的内容类型
*
* @return string|null
*/
public function getContentType(): ?string
{
return $this->request->getContentType();
}
/**
* 获取环境变量
*
@ -317,6 +327,16 @@ class Request
return $this->request->isAjax();
}
/**
* 判断是否为json
*
* @return boolean
*/
public function isJson(): bool
{
return $this->request->isJson();
}
/**
* 判断输入是否满足要求
*