protected static function mergePaths(Uri $baseUri, string $relative): string
    {
        $basePath = $baseUri->path();

        if ($baseUri->authority() !== null && $basePath === '') {
            return sprintf('/%s', $relative);
        }

        $last = strrpos($basePath, '/');

        if ($last !== false) {
            return sprintf('%s/%s', substr($basePath, 0, $last), $relative);
        }

        return $relative;
    }