private function addSelfLinkHeader($routeName, $routeType, Request $request)
    {
        $routeParams = $request->get('_route_params');
        if (!is_array($routeParams)) {
            $routeParams = [];
        }

        if (($routeType == 'post' || $routeType == 'postNoSlash') || $routeType != 'all') {
            // handle post request by rewriting self link to newly created resource
            $routeParams['id'] = $request->get('id');
        }

        // rewrite post routes to get
        if ($routeType == 'post' || $routeType == 'postNoSlash') {
            $parts = explode('.', $routeName);
            array_pop($parts);
            $parts[] = 'get';
            $routeName = implode('.', $parts);
        }

        $selfLinkUrl = $this->router->generate($routeName, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL);
        $queryString = $request->server->get('QUERY_STRING', '');

        // if no rql was set, we set our default current limits
        if ($request->attributes->get('paging') === true && strpos($queryString, 'limit(') === false) {
            $limit = sprintf(
                'limit(%s,%s)',
                $request->attributes->get('perPage'),
                $request->attributes->get('startAt')
            );

            if (!empty($queryString)) {
                $queryString .= '&';
            }

            $queryString .= $limit;
        }

        if (!empty($queryString)) {
            $selfLinkUrl .= '?' . strtr($queryString, [',' => '%2C']);
        }

        $this->linkHeader->add(
            new LinkHeaderItem(
                $selfLinkUrl,
                ['rel' => 'self']
            )
        );

        return $selfLinkUrl;
    }