public function paginate($page, $perPage, $total)
    {
        // set X-Total-Count header
        $this->response->setHeader('X-Total-Count', $total);

        // compute links
        $pageCount = max(1, ceil($total / $perPage));
        $base = $this->getEndpoint();

        $requestQuery = $this->request->query();

        // remove any previously set per_page value
        if (isset($requestQuery['per_page'])) {
            unset($requestQuery['per_page']);
        }

        // set the per_page value unless it's the default
        if ($perPage != self::DEFAULT_PER_PAGE) {
            $requestQuery['per_page'] = $perPage;
        }

        // self/first links
        $links = [
            'self' => $this->link($base, array_replace($requestQuery, ['page' => $page])),
            'first' => $this->link($base, array_replace($requestQuery, ['page' => 1])),
        ];

        // previous/next links
        if ($page > 1) {
            $links['previous'] = $this->link($base, array_replace($requestQuery, ['page' => $page - 1]));
        }

        if ($page < $pageCount) {
            $links['next'] = $this->link($base, array_replace($requestQuery, ['page' => $page + 1]));
        }

        // last link
        $links['last'] = $this->link($base, array_replace($requestQuery, ['page' => $pageCount]));

        // build Link header
        $linkStr = implode(', ', array_map(function ($link, $rel) {
            return "<$link>; rel=\"$rel\"";
        }, $links, array_keys($links)));

        $this->response->setHeader('Link', $linkStr);
    }