Adds node-specific link headers to appropriate responses.

@param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
Event containing the response.
162676
public function onResponse(FilterResponseEvent $event) {
    $response = $event->getResponse();

    $node = $this->getObject($response, 'node');

    if ($node === FALSE) {
      return;
    }

    $links = array_merge(
      $this->generateEntityReferenceLinks($node),
      $this->generateRelatedMediaLinks($node),
      $this->generateRestLinks($node)
    );

    // Add the link headers to the response.
    if (empty($links)) {
      return;
    }

    $response->headers->set('Link', $links, FALSE);
  }
931543
public function onKernelRequestIndex(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $semanticPathinfo = $request->attributes->get('semanticPathinfo') ?: '/';
        if (
            $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST
            && $semanticPathinfo === '/'
        ) {
            $indexPage = $this->configResolver->getParameter('index_page');
            if ($indexPage !== null) {
                $indexPage = '/' . ltrim($indexPage, '/');
                $request->attributes->set('semanticPathinfo', $indexPage);
                $request->attributes->set('needsForward', true);
            }
        }
    }
38274
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            // don't do anything if it's not the master request
            return;
        }

        $request = $event->getRequest();

        $requestUri = $request->getRequestUri();

        $requestUriNew = preg_replace('/-{2,}/', '-', $requestUri);

        if ($requestUri !== $requestUriNew) {
            $event->setResponse(new RedirectResponse($requestUriNew, 301));
            $event->stopPropagation();
        }
    }
555163
public function onCoreResponse(FilterResponseEvent $event)
    {
        $cms = $this->cmsSelector->retrieve();

        $response = $event->getResponse();
        $request = $event->getRequest();

        if ($this->cmsSelector->isEditor()) {
            $response->setPrivate();

            if (!$request->cookies->has('sonata_page_is_editor')) {
                $response->headers->setCookie(new Cookie('sonata_page_is_editor', '1'));
            }
        }

        $page = $cms->getCurrentPage();

        // display a validation page before redirecting, so the editor can edit the current page
        if (
            $page && $response->isRedirection() &&
            $this->cmsSelector->isEditor() &&
            !$request->get('_sonata_page_skip') &&
            !$this->skipRedirection
        ) {
            $response = new Response($this->templating->render('@SonataPage/Page/redirect.html.twig', [
                'response' => $response,
                'page' => $page,
            ]));

            $response->setPrivate();

            $event->setResponse($response);

            return;
        }

        if (!$this->decoratorStrategy->isDecorable($event->getRequest(), $event->getRequestType(), $response)) {
            return;
        }

        if (!$this->cmsSelector->isEditor() && $request->cookies->has('sonata_page_is_editor')) {
            $response->headers->clearCookie('sonata_page_is_editor');
        }

        if (!$page) {
            throw new InternalErrorException('No page instance available for the url, run the sonata:page:update-core-routes and sonata:page:create-snapshots commands');
        }

        // only decorate hybrid page or page with decorate = true
        if (!$page->isHybrid() || !$page->getDecorate()) {
            return;
        }

        $parameters = [
            'content' => $response->getContent(),
        ];

        $response = $this->pageServiceManager->execute($page, $request, $parameters, $response);

        if (!$this->cmsSelector->isEditor() && $page->isCms()) {
            $response->setTtl($page->getTtl());
        }

        $event->setResponse($response);
    }
1254785
public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($this->configurationHandler->isRedirectOption(PlatformDefaults::$REDIRECT_OPTIONS['LAST'])) {
            $this->saveLastUri($event);
        }
    }
28131
public function onKernelResponse(FilterResponseEvent $event): void
    {
        $link = new Link('mercure', $this->hub);

        $attributes = $event->getRequest()->attributes;
        if (
            null === ($resourceClass = $attributes->get('_api_resource_class')) ||
            false === $this->resourceMetadataFactory->create($resourceClass)->getAttribute('mercure', false)
        ) {
            return;
        }

        if (null === $linkProvider = $attributes->get('_links')) {
            $attributes->set('_links', new GenericLinkProvider([$link]));

            return;
        }

        $attributes->set('_links', $linkProvider->withLink($link));
    }
1261887
public function onResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($request->isMethodSafe(false)) {
            return;
        }

        // In case we're using 'preview', the `_route` has been set to `contentlink`, because we're
        // viewing a single page, but `_original_route` will be `preview`, which should take
        // precedence, if set. See PR https://github.com/bolt/bolt/pull/7458
        /** @deprecated since 3.4 to be removed in 4.0 */
        $route = $request->attributes->get('_internal_route', $request->attributes->get('_route'));

        if (!in_array($route, $this->routes)) {
            return;
        }

        $response = $event->getResponse();

        if ($response->isRedirection() || $response->isEmpty() || $response->isInformational()) {
            return;
        }

        $response->headers->set('X-XSS-Protection', 0);
    }
401634
public function onKernelResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$configuration = $request->attributes->get('_cache')) {
            return;
        }

        $response = $event->getResponse();

        // http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-12#section-3.1
        if (!\in_array($response->getStatusCode(), [200, 203, 300, 301, 302, 304, 404, 410])) {
            return;
        }

        if (!$response->headers->hasCacheControlDirective('s-maxage') && null !== $age = $configuration->getSMaxAge()) {
            $age = $this->convertToSecondsIfNeeded($age);

            $response->setSharedMaxAge($age);
        }

        if ($configuration->mustRevalidate()) {
            $response->headers->addCacheControlDirective('must-revalidate');
        }

        if (!$response->headers->hasCacheControlDirective('max-age') && null !== $age = $configuration->getMaxAge()) {
            $age = $this->convertToSecondsIfNeeded($age);

            $response->setMaxAge($age);
        }

        if (!$response->headers->hasCacheControlDirective('max-stale') && null !== $stale = $configuration->getMaxStale()) {
            $stale = $this->convertToSecondsIfNeeded($stale);

            $response->headers->addCacheControlDirective('max-stale', $stale);
        }

        if (!$response->headers->has('Expires') && null !== $configuration->getExpires()) {
            $date = \DateTime::createFromFormat('U', strtotime($configuration->getExpires()), new \DateTimeZone('UTC'));
            $response->setExpires($date);
        }

        if (!$response->headers->has('Vary') && null !== $configuration->getVary()) {
            $response->setVary($configuration->getVary());
        }

        if ($configuration->isPublic()) {
            $response->setPublic();
        }

        if ($configuration->isPrivate()) {
            $response->setPrivate();
        }

        if (!$response->headers->has('Last-Modified') && isset($this->lastModifiedDates[$request])) {
            $response->setLastModified($this->lastModifiedDates[$request]);

            unset($this->lastModifiedDates[$request]);
        }

        if (!$response->headers->has('Etag') && isset($this->etags[$request])) {
            $response->setEtag($this->etags[$request]);

            unset($this->etags[$request]);
        }
    }
1138897
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $attributes = $request->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        if (!$attributes->has('itemType')) {
            return;
        }

        $config = $this->loadConfig($attributes->get('itemType'));

        $customParams = $request->query->get('customParams', []);
        if (!is_array($customParams)) {
            throw new RuntimeException(
                sprintf(
                    'Invalid custom parameters specification for "%s" item type.',
                    $attributes->get('itemType')
                )
            );
        }

        $config->addParameters($customParams);

        $configLoadEvent = new ConfigLoadEvent($config);

        Kernel::VERSION_ID >= 40300 ?
            $this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) :
            $this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent);

        $this->container->set('netgen_content_browser.current_config', $config);
    }
253831
public function onEvent(Event $event): void
    {
        if (!$event instanceof GetResponseEvent || !$this->injected) {
            if (null !== ($filter = $this->getFilter())) {
                $this->injectParameters($filter);
            }
        }
    }
898644
public function onKernelResponse(FilterResponseEvent $event)
    {
        if (!$event->isMasterRequest())
        {
            return;
        }

        $attributes = $event->getRequest()->attributes->all();

        if( array_key_exists('_callable', $attributes) && array_key_exists('0', $attributes['_callable']) && is_object($attributes['_callable'][0]))
        {
            $attributes['_callable'][0]->postAction();
        }
    }
1229763
public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($event->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        if ($event->getRequest()->isXmlHttpRequest()) {
            return;
        }

        if ($this->joomla->getState() === JoomlaInterface::STATE_RESPONSE) {
            return;
        }

        $menu = $this->pathMatcher->findMenuPointForRequest($event->getRequest());

        if ($menu === null) {
            $match = false;

            foreach ($this->pattern as $pattern) {
                if (preg_match('#' . $pattern . '#i', $event->getRequest()->getPathInfo())) {
                    $match = true;
                    break;
                }
            }

            if (!$match) {
                return;
            }
        }

        $response = $event->getResponse();
        $contentType = $response->headers->get('Content-Type');

        if ($contentType === null || $contentType === 'text/html') {
            $helper = new JoomlaControllerHelper(
                $this->joomla,
                $event->getRequest(),
                $this->factory
            );

            $newResponse = $helper->wrapResponse($response, $menu);
            $response->setContent($newResponse->getContent());
        }
    }
963040
public function onKernelResponse(FilterResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $response = $event->getResponse();

        if ($response instanceof StreamedResponse) {
            $response->send();
        }
    }
1045767
public function onKernelResponse(FilterResponseEvent $event)
    {
        if (HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) {
            return;
        }

        if (!in_array($event->getRequest()->get('_route'), $this->routes)) {
            return;
        }

        $response = $event->getResponse();
        $varyHeaders = $response->headers->get('vary', null, false);

        foreach ($this->userIdentifierHeaders as $removableVary) {
            unset($varyHeaders[array_search(strtolower($removableVary), $varyHeaders)]);
        }
        $response->setVary($varyHeaders, true);
    }
476292
public function onKernelResponse(FilterResponseEvent $event)
    {
        $master = HttpKernelInterface::MASTER_REQUEST === $event->getRequestType();
        if ($this->onlyMasterRequests && !$master) {
            return;
        }

        if ($this->onlyException && null === $this->exception) {
            return;
        }

        $request = $event->getRequest();
        $exception = $this->exception;
        $this->exception = null;

        $dataToSend = $this->collector->collect($master, $request, $event->getResponse(), $exception);

        if (null === $dataToSend || !\is_array($dataToSend) || \count($dataToSend) < 1) {
            return;
        }
        $this->collector->send($dataToSend);
    }
265446
public function onKernelRequest(Event\GetResponseEvent $event)
    {
        if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
            $request = $event->getRequest();
            $publicUrl = rawurldecode($request->getRequestUri());

            if ($this->isExcluded($publicUrl)) {
                // don't process urls which are marked as excluded.
                return;
            }

            if ($this->isParamsEnabled) {
                if (false !== ($queryMark = strpos($publicUrl, '?'))) {
                    $originalUrl = $publicUrl;
                    $publicUrl = substr($originalUrl, 0, $queryMark);
                    $queryString = substr($originalUrl, $queryMark);
                } else {
                    $queryString = null;
                }

                $parts = explode('/', $publicUrl);
                $params = [];
                while (false !== strpos(end($parts), '=')) {
                    array_push($params, array_pop($parts));
                }
                if ($params) {
                    $publicUrl = join('/', $parts);

                    $parser = new UriParser();
                    $request->query->add($parser->parseUri(join('/', array_reverse($params))));

                    if (!$this->aliasing->hasInternalAlias($publicUrl, false)) {
                        $this->rewriteRequest($event, $publicUrl . $queryString);

                        return;
                    }
                }
            }

            /** @var UrlAlias $url */
            if ($url = $this->aliasing->hasInternalAlias($publicUrl, true)) {
                switch ($url->getMode()) {
                    case UrlAlias::REWRITE:
                        $this->rewriteRequest($event, $url->getInternalUrl());
                        break;
                    case UrlAlias::MOVE:
                    case UrlAlias::ALIAS:
                        $event->setResponse(new RedirectResponse($url->getInternalUrl(), $url->getMode()));
                        break;
                    default:
                        throw new \UnexpectedValueException(
                            sprintf(
                                'Invalid mode %s for UrlAlias %s.',
                                $url->getMode(),
                                json_encode($url)
                            )
                        );
                }
            } elseif (strpos($publicUrl, '?') !== false) {
                // allow aliases to receive the query string.

                $publicUrl = substr($publicUrl, 0, strpos($publicUrl, '?'));
                if ($url = $this->aliasing->hasInternalAlias($publicUrl, true, UrlAlias::REWRITE)) {
                    $this->rewriteRequest($event, $url->getInternalUrl());

                    return;
                }
            }
        }
    }
96808
public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();

        if ($response instanceof SerializedResponse) {
            $acceptableContentTypes = $event->getRequest()->getAcceptableContentTypes();

            $format = 'json';

            foreach ($acceptableContentTypes as $item) {
                if (strpos($item, 'xml') !== false) {
                    $format = 'xml';
                    break;
                }
            }

            $serializedData = $this->serializer->serialize($response->getData(), $format, null);

            $response->setContent($serializedData);
        }
    }