getUri(); $path = $this->normalize($uri->getPath()); if ($this->responseFactory && ($uri->getPath() !== $path)) { return $this->responseFactory->createResponse(301) ->withHeader('Location', (string) $uri->withPath($path)); } $response = $handler->handle($request); return $response; } private function normalize(string $path): string { if ($path === '') { return '/'; } if (strlen($path) > 1) { return rtrim($path, '/'); } return $path; } }