mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Fixed 500 caused by empty body. (#1964)
This commit is contained in:
parent
c67160fe96
commit
33bcb55969
@ -1,8 +1,12 @@
|
||||
# v2.0.1 - TBD
|
||||
|
||||
## Fixed
|
||||
|
||||
- [#1964](https://github.com/hyperf/hyperf/pull/1964) Fixed http status code 500 caused by empty body.
|
||||
|
||||
## Optimized
|
||||
|
||||
[#1959](https://github.com/hyperf/hyperf/pull/1959) Make ClassLoader easier to be extended.
|
||||
- [#1959](https://github.com/hyperf/hyperf/pull/1959) Make ClassLoader easier to be extended.
|
||||
|
||||
# v2.0.0 - 2020-06-22
|
||||
|
||||
|
@ -480,8 +480,8 @@ class Request extends \Hyperf\HttpMessage\Base\Request implements ServerRequestI
|
||||
|
||||
try {
|
||||
$parser = static::getParser();
|
||||
if ($parser->has($contentType)) {
|
||||
$data = $parser->parse($request->getBody()->getContents(), $contentType);
|
||||
if ($parser->has($contentType) && $content = $request->getBody()->getContents()) {
|
||||
$data = $parser->parse($content, $contentType);
|
||||
}
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
throw new BadRequestHttpException($exception->getMessage());
|
||||
|
@ -93,6 +93,22 @@ class ServerRequestTest extends TestCase
|
||||
$this->assertSame([], RequestStub::normalizeParsedBody($json, $request));
|
||||
}
|
||||
|
||||
public function testNormalizeEmptyBody()
|
||||
{
|
||||
$this->getContainer();
|
||||
|
||||
$json = ['name' => 'Hyperf'];
|
||||
$request = Mockery::mock(RequestInterface::class);
|
||||
$request->shouldReceive('getHeaderLine')->with('content-type')->andReturn('application/json; charset=utf-8');
|
||||
$request->shouldReceive('getBody')->andReturn(new SwooleStream(''));
|
||||
$this->assertSame($json, RequestStub::normalizeParsedBody($json, $request));
|
||||
|
||||
$request = Mockery::mock(RequestInterface::class);
|
||||
$request->shouldReceive('getHeaderLine')->with('content-type')->andReturn('application/json; charset=utf-8');
|
||||
$request->shouldReceive('getBody')->andReturn(new SwooleStream(''));
|
||||
$this->assertSame([], RequestStub::normalizeParsedBody([], $request));
|
||||
}
|
||||
|
||||
public function testNormalizeParsedBodyInvalidContentType()
|
||||
{
|
||||
$this->getContainer();
|
||||
|
Loading…
Reference in New Issue
Block a user