diff --git a/http-server/Service/Http.php b/http-server/Service/Http.php index 92f65495..c420c5f7 100644 --- a/http-server/Service/Http.php +++ b/http-server/Service/Http.php @@ -42,15 +42,13 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect public function onRequest(Request $request, Response $response): void { try { - $node = $this->router->radix_tree($Psr7Request = ScRequest::create($request)); - if (!($node instanceof Node)) { + if (!(($node = $this->router->radix_tree($Psr7Request = ScRequest::create($request))) instanceof Node)) { throw new RequestException(Constant::STATUS_404_MESSAGE, 404); } if (!(($psr7Response = $node->dispatch($Psr7Request)) instanceof ResponseInterface)) { $psr7Response = $this->transferToResponse($psr7Response); } - $request_time_float = $request->server['request_time_float'] - $request->server['request_time']; - $psr7Response->withHeader('Run-Time', microtime(true) - $request_time_float); + $psr7Response->withHeader('Run-Time', $this->_runTime($request)); } catch (Error | \Throwable $exception) { $psr7Response = $this->exceptionHandler->emit($exception, $this->response); } finally { @@ -60,6 +58,16 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect } + /** + * @param Request $request + * @return float + */ + private function _runTime(Request $request): float + { + return round(microtime(true) - ($request->server['request_time_float'] - $request->server['request_time']), 6); + } + + /** * @param mixed $responseData * @return ResponseInterface