Follow a redirect chain until a non-redirect is received.

@param  \Illuminate\Http\Response  $response
@return \Illuminate\Http\Response
325330
protected function followRedirects($response)
    {
        while ($response->isRedirect()) {
            $response = $this->get($response->headers->get('Location'));
        }

        $this->followRedirects = false;

        return $response;
    }
584207
public function send(KDispatcherResponseInterface $response)
    {
        if($response->isRedirect())
        {
            $session  = $response->getUser()->getSession();

            //Set the messages into the session
            $messages = $response->getMessages();
            if(count($messages))
            {
                //Auto start the session if it's not active.
                if(!$session->isActive()) {
                    $session->start();
                }

                $session->getContainer('message')->add($messages);
            }

            //Set the redirect into the response
            $response->setContent(sprintf(
                '<!DOCTYPE html>
                    <html>
                        <head>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                            <noscript>
                                <meta http-equiv="refresh" content="1;url=%1$s" />
                            </noscript>
                            <title>Redirecting to %1$s</title>
                        </head>
                        <body onload="window.location = \'%1$s\'">
                            Redirecting to <a href="%1$s">%1$s</a>.
                        </body>
                    </html>'
                , htmlspecialchars($response->headers->get('Location'), ENT_QUOTES, 'UTF-8')
            ), 'text/html');

            return parent::send($response);
        }
    }
469071
public function run(Request $request, Response $response) : Response {

		$strict = $this->getParam('STRICT_ROUTING');
		$case = $this->getParam('CASE_SENSITIVE');
		$method = $request->getMethod();
		$url = $request->getUri()->getPath();

		//Matching
		foreach($this->routes as $route) {
			if($route->match($url, $strict, $case) && $method == $route->getMethod()) {
				return $route->call($request, $response);
			} elseif($route->match($url, $strict, $case) && $method == 'HEAD') {
				$body = $response->getBody();
				$body->close();
				$response = $response->withBody($body);
				return $response;
			}
		}

		//Error
		$methods = array();
		foreach($this->routes as $route) {
			array_push($methods, $route->getMethod());
			if($route->match($url, $strict, $case) && $method != $route->getMethod() && in_array($method, self::$_METHODS))
				return call_user_func($this->httpErrors['405'], $request, $response);

			elseif($route->match($url, $strict, $case) && $method != $route->getMethod() && !in_array($method, self::$_METHODS))
				return call_user_func($this->httpErrors['400'], $request, $response);
		}

		if(!in_array($method, $methods) && !in_array($method, self::$_METHODS))
			return call_user_func($this->httpErrors['400'], $request, $response);
		else
			return call_user_func($this->httpErrors['404'], $request, $response);
		
	}
1320686
protected function setNeededAction(Response $response) {
        if ($response->hasHtml())
        {
            $response->setNeededAction(Response::NEEDED_SHOW_HTML);
        }
        elseif ($response->isProcessing())
        {
            $response->setNeededAction(Response::NEEDED_STATUS_UPDATE);
        }
    }
228475
public function setResponse($response)
    {
        $this->response = (null !== $response) ? (string) $response : null;
        return $this;
    }
442851
protected function _redirect(ServerRequest $request, Response $response) {
		$message = $request->getSession()->consume($this->_config['flashKey']);
		$url = $response->getHeader('Location')[0];
		$status = $response->getStatusCode();

		$json = JsonEncoder::encode([
			// Error and content are here to make the output the same as previously
			// with the component, so existing unit tests don't break.
			'error' => null,
			'content' => null,
			'_message' => $message,
			'_redirect' => compact('url', 'status'),
		], $this->_config['jsonOptions']);

		$response = $response->withStatus(200)
			->withoutHeader('Location')
			->withHeader('Content-Type', 'application/json; charset=' . $response->getCharset())
			->withStringBody($json);

		return $response;
	}
1071247
public function next(Request $request, Response $response, $next)
    {
        $response->setContentType('text/json');
        $next($request, $response);
    }
1030008
public function handle(
        ServerRequestInterface $request, ResponseInterface $response
    )
    {
        $this->request = $request;
        $render = $this->request->getAttribute('render', true);
        if ($render) {
            $response = $this->render($response);
        }
        return $this->executeNext($request, $response);
    }
136918
public function isRedirection($response) {
        $status = $response->getHeaders()->get('Status');
        $code   = (int)strstr($status,' ',true);
        return $code >= 300 && $code < 400;
    }
779336
protected function respond($response)
    {
        if (Arr::get($response, 'object') === 'list') {
            if (!empty($response['data'])) {
                foreach ($response['data'] as $responseItem) {
                    $success = Arr::get($responseItem, 'object', 'error') !== 'error';

                    $responses[] = $this->mapResponse($success, $responseItem);
                }

                return $responses;
            } else {
                $response = $response['data'];
            }
        }

        $success = Arr::get($response, 'object', 'error') !== 'error';

        return $this->mapResponse($success, $response);
    }
249343
public function handle(ServerRequestInterface $request, Response $response)
    {
        $server = $request->getServerParams();
        $server['REQUEST_METHOD'] = $request->getMethod();
        $server['REQUEST_URI'] = $request->getUri()->getPath();
        $globals = [
            '_GET' => $request->getQueryParams(),
            '_POST' => $request->getParsedBody()
        ];
        $req = $this->router->match($globals, $server);
        $resourceObject = $this->resource->{$req->method}->uri($req->path)->withQuery($req->query)->eager->request();
        $response = $this->toPsr7Response($response, $resourceObject);

        return $response;
    }
509997
public function next($response): ?callable
    {
        if ($this->isEmpty()) {
            return null;
        }

        if (!is_null($response)) {
            return null;
        }

        return $this->pop();
    }
912337
protected function _withCustomHeaders($response)
    {
        foreach ((array)$this->getConfig('headers') as $key => $value) {
            $response = $response->withHeader($key, $value);
        }

        return $response;
    }
211000
protected function handleResponse(Response $response)
    {
        $statusCode = $response->getStatusCode();

        switch ($statusCode) {
            case 401:
                $response = $this->processNotAuthorized();
                break;
        }

        return $response;
    }
771593
public function afterSend($response)
    {
        $this->client->afterSend($this, $response);

        $event = new RequestEvent();
        $event->request = $this;
        $event->response = $response;
        $this->trigger(self::EVENT_AFTER_SEND, $event);
    }
1319594
protected function returnResponse(ResponseInterface $response): ResponseInterface
    {
        $this->nextHandler = null;
        reset($this->handlers);
        return $response;
    }
478399
protected function finish(Response $response)
    {
        if ($this->requestedResultsLocale !== '') {
            $this->getLocalization()->popActiveContext();
        }
        if (!$response->headers->has('X-Frame-Options')) {
            $response->headers->set('X-Frame-Options', 'DENY');
        }
        if (!$response->headers->has('Access-Control-Allow-Origin')) {
            $config = $this->app->make('community_translation/config');
            $response->headers->set('Access-Control-Allow-Origin', (string) $config->get('options.api.accessControlAllowOrigin'));
        }

        return $response;
    }