Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/Util/Http/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,6 @@ public function getParsedBody()
$parsedBody = &$this->parsedBody;
if (null === $parsedBody)
{
if (!$this->bodyInited)
{
$this->initBody();
$this->bodyInited = true;
}
$contentType = $this->getHeaderLine(RequestHeader::CONTENT_TYPE);
if ('' === $contentType)
{
Expand All @@ -311,7 +306,7 @@ public function getParsedBody()
// json
elseif (MediaType::APPLICATION_JSON === $contentType)
{
$content = $this->body->getContents();
$content = $this->getBody()->getContents();
if ('' !== $content)
{
$parsedBody = json_decode($content, !Config::get('@currentServer.jsonBodyIsObject', false), 512, \JSON_THROW_ON_ERROR);
Expand All @@ -331,7 +326,7 @@ public function getParsedBody()
]))
{
$this->post = $parsedBody = new \DOMDocument();
$parsedBody->loadXML($this->body->getContents());
$parsedBody->loadXML($this->getBody()->getContents());
}
// 其它
else
Expand Down
13 changes: 3 additions & 10 deletions tests/unit/Component/Tests/Util/Http/ServerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,14 @@ private function __testParsedBody(string $type): void
$this->assertEquals(['name' => 'imi'], $request->getParsedBody());

// form
$request = new class() extends ServerRequest {
/**
* {@inheritDoc}
*/
protected function initBody(): void
{
$this->post = ['name' => 'imi'];
}
};
$request = new ServerRequest();
foreach ([
MediaType::APPLICATION_FORM_URLENCODED,
MediaType::MULTIPART_FORM_DATA,
] as $contentType)
{
$request->setHeader(RequestHeader::CONTENT_TYPE, $contentType);
$request->setPost(['name' => 'imi'])
->setHeader(RequestHeader::CONTENT_TYPE, $contentType);
$requestTmp = $request->withMethod(RequestMethod::POST);
$this->assertEquals(['name' => 'imi'], $requestTmp->getParsedBody());
$requestTmp = $request->withMethod(RequestMethod::PUT);
Expand Down
Loading