Merge pull request #2140 from Reasno/session

fix: save session even if an exception is thrown
This commit is contained in:
李铭昕 2020-07-20 15:09:11 +08:00 committed by GitHub
commit b5ff17eda1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -1,3 +1,9 @@
# v2.0.4 - TBD
## Fixed
- [#2140](https://github.com/hyperf/hyperf/pull/2140) Fixed a case where session are not saved when exception occurs.
# v2.0.3 - TBD
## Added

View File

@ -54,16 +54,14 @@ class SessionMiddleware implements MiddlewareInterface
$session = $this->sessionManager->start($request);
$response = $handler->handle($request);
try {
$response = $handler->handle($request);
} finally {
$this->storeCurrentUrl($request, $session);
$this->sessionManager->end($session);
}
$this->storeCurrentUrl($request, $session);
$response = $this->addCookieToResponse($request, $response, $session);
// @TODO Use defer
$this->sessionManager->end($session);
return $response;
return $this->addCookieToResponse($request, $response, $session);
}
private function isSessionAvailable(): bool