Modifies the response status code. Checks for cross domain redirects and
blocks them.

@param Request  $request
@param Response $response
170872
private function modifyStatusCode(Request $request, Response $response)
    {
        if ($request->headers->has(self::ORIGIN_REQUEST_HEADER)
            && $response->headers->has(self::ORIGIN_RESPONSE_HEADER)
            && !$this->haveSameOrigin($request, $response)
        ) {
            $response->setStatusCode(Response::HTTP_FORBIDDEN);
        }
    }
1019444
public function resolve(Request $request, Response $response, UriPath $uriPath)
    {
        if ($this->target instanceof HttpUri) {
            $targetUri = $this->target;
        } else {
            $targetUri = $request->uri()->withPath($this->target);
        }

        $response->redirect($targetUri, $this->statusCode);
    }
1255880
protected function injectAlertify(Response $response, Request $request)
    {
        $content = $response->getContent();
        $endBodyPos = strripos($content, '</body>');
        $hasBody = false !== $endBodyPos;
        $hasMetaRefresh = false !== strripos($content, 'http-equiv="refresh"');
        $forceInject = $response->headers->get('X-Inject-Alertify', false);
        $isRedirectResponse = $response instanceof RedirectResponse;

        if ($hasBody && !$hasMetaRefresh && !$isRedirectResponse || $forceInject) {
            if ($response->getStatusCode() === 204) {
                throw new IncompatibleStatusCodeException();
            }
            $alertify = $this->alertifySessionHandler->handle($this->session, $this->twig);
            if ($endBodyPos) {
                $content = substr($content, 0, $endBodyPos).$alertify.substr($content, $endBodyPos);
            } else {
                $content .= $alertify;
            }
            $response->setContent($content);
        }
    }
1020804
public function resolve(Request $request, Response $response)
    {
        return $response->methodNotAllowed(
                $request->method(),
                $this->allowedMethods
        );
    }
1315676
public function postRequest(HTTPRequest $request, HTTPResponse $response = null)
    {
        if ($response &&
            preg_match('/text\/html/', $response->getHeader('Content-Type')) &&
            !preg_match('/^(admin|dev)\//', $request->getURL())
        ) {
            $response->setBody(
                $this->obfuscateEmails($response->getBody())
            );
        }
    }
530173
public function run(Request $request, Response $response)
    {
        $this["logger.service"]("System")->info("Beginning process for request.", [$request]);

        $this->setRequestProperties($request);

        $result = $this["hooks.service"]->exec(
            "application.dispatch.before",
            $request,
            $response,
            $this
        );
        if ($result === "exit"
            || (is_array($result) && in_array("exit", $result))) {
            return;
        }

        // record the time before execution
        $start = microtime(true);

        // dispatch request
        try {
            $this["routeDispatcher.service"]->dispatch($request, $response, $this);
        } catch (RouteNotFoundException $routeNotFound) {
            $this["logger.service"]("System")->error("No Route found for Request");
            $this["logger.service"]("System")->debug(
                "No Route Found Debug Information",
                ["exception" => $routeNotFound]
            );

            $response->setStatusCode(404);
            $response->setContent($this->load404Page());
            throw $routeNotFound;
        }

        $this["logger.service"]("System")->info(
            "Request has finished processing, Response is ready to be sent to "
            . "caller."
        );

        $this["hooks.service"]->exec("application.dispatch.after");

        // record the time after execution
        $end = microtime(true);
        $this["logger.service"]("System")->debug(
            "Time taken to finish Request processing",
            [
                "start"     =>  $start,
                "end"       =>  $end,
                "elapsed"   =>  $end - $start,
                "uri"       =>  $request->getRequestUri()
            ]
        );
    }
1290348
protected function setUriHeader(Response $response, Request $request)
    {
        $response->header('X-PJAX-URL', $request->getRequestUri());

        return $this;
    }
322774
public function modifyRequest(
        RequestInterface $request,
        array $options,
        ResponseInterface $response
    ) {
        // Request modifications to apply.
        $modify = [];
        $protocols = $options['allow_redirects']['protocols'];

        // Use a GET request if this is an entity enclosing request and we are
        // not forcing RFC compliance, but rather emulating what all browsers
        // would do.
        $statusCode = $response->getStatusCode();
        if ($statusCode == 303 ||
            ($statusCode <= 302 && $request->getBody() && !$options['allow_redirects']['strict'])
        ) {
            $modify['method'] = 'GET';
            $modify['body'] = '';
        }

        $modify['uri'] = $this->redirectUri($request, $response, $protocols);
        Psr7\rewind_body($request);

        // Add the Referer header if it is told to do so and only
        // add the header if we are not redirecting from https to http.
        if ($options['allow_redirects']['referer']
            && $modify['uri']->getScheme() === $request->getUri()->getScheme()
        ) {
            $uri = $request->getUri()->withUserInfo('', '');
            $modify['set_headers']['Referer'] = (string) $uri;
        } else {
            $modify['remove_headers'][] = 'Referer';
        }

        // Remove Authorization header if host is different.
        if ($request->getUri()->getHost() !== $modify['uri']->getHost()) {
            $modify['remove_headers'][] = 'Authorization';
        }

        return Psr7\modify_request($request, $modify);
    }
67715
protected function processCacheSettings(Request $request, Response $response): void
    {
        $defaultSharedMaxAge = $this->getConfigResolver()->getParameter('view.shared_max_age', 'ngsite');

        $cacheSettings = $request->attributes->get('cacheSettings');
        if (!is_array($cacheSettings)) {
            $cacheSettings = ['sharedMaxAge' => $defaultSharedMaxAge];
        }

        $public = true;

        if (isset($cacheSettings['sharedMaxAge'])) {
            $response->setSharedMaxAge($cacheSettings['sharedMaxAge']);
            if (empty($cacheSettings['sharedMaxAge'])) {
                $public = false;
            }
        } elseif (isset($cacheSettings['maxAge'])) {
            $response->setMaxAge($cacheSettings['maxAge']);
            if (empty($cacheSettings['maxAge'])) {
                $public = false;
            }
        } else {
            $response->setSharedMaxAge($defaultSharedMaxAge);
        }

        $public ? $response->setPublic() : $response->setPrivate();
    }
1362466
public function log(Request $request, Response $response): void
    {
        $host = $request->url();
        $method = $request->method();
        $agent = $request->userAgent();
        $date = $this->date($response->getDate());
        $status = $response->status();
        $style = $this->style($status);

        $this->output->writeln(
            sprintf("%s %s %s <$style>%d</$style> %s", $host, $date, $method, $status, $agent)
        );
    }
708198
public function resolve(Request $request, Response $response)
    {
        $allowedMethods = $this->matchingRoutes->allowedMethods();
        if (!in_array(Http::OPTIONS, $allowedMethods)) {
            $allowedMethods[] = Http::OPTIONS;
        }

        $response->addHeader('Allow', join(', ', $allowedMethods))
                ->addHeader(
                        'Access-Control-Allow-Methods',
                        join(', ', $allowedMethods)
                );
    }
958907
public function handle(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        $type = 'psr-7';
        $this->cors->setRequest($type, $request);
        $this->cors->setResponse($type, $response);
        $this->cors->handle();

        return $this->cors->getResponse();
    }
111229
public function modifyResponse(Request $request, ResponseInterface $response)
    {
        if (!$this->isEnabled() || $response instanceof JsonResponse) {
            return $response;
        }

        return $this->injectDebugBar($response);
    }
1197861
protected function setUriHeader(Request $request, Response $response)
    {
        $response->headers->set('X-PJAX-URL', $request->getUrl());

        return $this;
    }
1116303
protected function sendResetResponse(Request $request, $response): JsonResponse
    {
        $user = (new HCAuthorizeDTO(
            $this->user,
            $this->user->createToken('Personal Access Token'),
            $this->getUserConfig($this->user)
        ))->toArray();

        return $this->response->success(trans($response), $user);
    }
1143100
public function executeTerminators(Request $request, Response $response): Response
    {
        $middlewares = $this->filterMiddleware(Terminator::class);

        foreach ($middlewares as $middleware) {
            $response = $middleware->doTerminate($request, $response);
        }

        unset($middlewares);

        return $response;
    }
1135138
public function afterSend($request, $response)
    {
        $event = new RequestEvent();
        $event->request = $request;
        $event->response = $response;
        $this->trigger(self::EVENT_AFTER_SEND, $event);
    }