private function generateLink($routeName, $page, $perPage, $type, Request $request, $rql)
    {
        $limit = '';
        if ($perPage) {
            $page = ($page - 1) * $perPage;
            $limit = sprintf('limit(%s,%s)', $perPage, $page);
        }
        if (strpos($rql, 'limit') !== false) {
            $rql = preg_replace('/limit\(.*\)/U', $limit, $rql);
        } elseif (empty($rql)) {
            $rql .= $limit;
        } else {
            $rql .= '&'.$limit;
        }

        $url = $this->getRqlUrl(
            $request,
            $this->router->generate($routeName, [], UrlGeneratorInterface::ABSOLUTE_URL) .
            '?' . strtr($rql, [',' => '%2C'])
        );

        $this->linkHeader->add(new LinkHeaderItem($url, array('rel' => $type)));
    }