private static function normalizePath($uri, $path = null)
    {
        if ($path instanceof PathInterface) {
            $path = $path->getContent();
        }

        $path = $path ?? $uri->getPath();
        $path = (string) $path;
        if (null !== $uri->getAuthority()
            && '' !== $uri->getAuthority()
            && '' !== $path
            && '/' != ($path[0] ?? '')
        ) {
            return $uri->withPath('/'.$path);
        }

        return $uri->withPath($path);
    }