mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Added method Hyperf\HttpServer\Request::clearStoredParsedData()
. (#3514)
* Added method `Hyperf\HttpServer\Request::clearStoredParsedData()`. * Added test cases Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
4be1f519cd
commit
6cea3ce4de
@ -5,6 +5,10 @@
|
||||
- [#3510](https://github.com/hyperf/hyperf/pull/3510) Fixed bug that consult couldn't force a node into the left state.
|
||||
- [#3513](https://github.com/hyperf/hyperf/pull/3513) Fixed nats connection closed accidentally when socket timeout is smaller than max idle time.
|
||||
|
||||
## Added
|
||||
|
||||
- [#3514](https://github.com/hyperf/hyperf/pull/3514) Added method `Hyperf\HttpServer\Request::clearStoredParsedData()`.
|
||||
|
||||
# v2.1.15 - 2021-04-19
|
||||
|
||||
## Added
|
||||
|
@ -503,6 +503,13 @@ class Request implements RequestInterface
|
||||
return $this->call(__FUNCTION__, func_get_args());
|
||||
}
|
||||
|
||||
public function clearStoredParsedData(): void
|
||||
{
|
||||
if (Context::has($this->contextkeys['parsedData'])) {
|
||||
Context::set($this->contextkeys['parsedData'], null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the given file is a valid SplFileInfo instance.
|
||||
* @param mixed $file
|
||||
|
@ -94,4 +94,21 @@ class RequestTest extends TestCase
|
||||
$psrRequest = new Request();
|
||||
$this->assertSame(['id' => 1, 'name' => 'Hyperf'], $psrRequest->inputs(['id', 'name'], ['name' => 'Hyperf']));
|
||||
}
|
||||
|
||||
public function testClearStoredParsedData()
|
||||
{
|
||||
$psrRequest = new \Hyperf\HttpMessage\Server\Request('GET', '/');
|
||||
$psrRequest = $psrRequest->withParsedBody(['id' => 1]);
|
||||
Context::set(ServerRequestInterface::class, $psrRequest);
|
||||
|
||||
$request = new Request();
|
||||
$this->assertSame(['id' => 1], $request->all());
|
||||
|
||||
$psrRequest = $psrRequest->withParsedBody(['id' => 1, 'name' => 'hyperf']);
|
||||
Context::set(ServerRequestInterface::class, $psrRequest);
|
||||
$this->assertSame(['id' => 1], $request->all());
|
||||
|
||||
$request->clearStoredParsedData();
|
||||
$this->assertSame(['id' => 1, 'name' => 'hyperf'], $request->all());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user