public function buildResponse(GetResponseForControllerResultEvent $event)
    {
        $request = $event->getRequest();

        if (
            !$request->attributes->has(RouteKeys::ACTION) ||
            $request->attributes->get(RouteKeys::ACTION) !== 'capabilities'
        ) {
            return;
        }

        $routes = $event->getControllerResult();
        $response = new Response;
        $links = $response->headers->get('Link', null, false);

        foreach ($routes as $name => $route) {
            $definition = $route->getDefault(RouteKeys::DEFINITION);
            list($collection, $resource) = explode('::', $definition);
            $definition = $this
                ->registry
                ->getCollection($collection)
                ->getResource($resource);

            $links[] = sprintf(
                '<%s>; rel="endpoint"; name="%s_%s"',
                $this->urlGenerator->generate($name),
                $definition->getCollection(),
                $definition
            );
        }

        $response->headers->add(['Link' => $links]);
        $event->setResponse($response);
    }