Rewind the entity body of the request if needed

@param RequestInterface $redirectRequest
@throws CouldNotRewindStreamException
973328
public static function rewindEntityBody(RequestInterface $redirectRequest)
    {
        // Rewind the entity body of the request if needed
        if ($body = $redirectRequest->getBody()) {
            // Only rewind the body if some of it has been read already, and
            // throw an exception if the rewind fails
            if ($body->tell() && !$body->seek(0)) {
                throw new CouldNotRewindStreamException(
                    'Unable to rewind the non-seekable request body after redirecting',
                    $redirectRequest
                );
            }
        }
    }
1371934
private function createRequest(RequestInterface $request)
    {
        $options = [
            'exceptions' => false,
            'allow_redirects' => false,
        ];

        $options['version'] = $request->getProtocolVersion();
        $options['headers'] = $request->getHeaders();
        $body = (string) $request->getBody();
        $options['body'] = '' === $body ? null : $body;

        return $this->client->createRequest(
            $request->getMethod(),
            (string) $request->getUri(),
            $options
        );
    }
81107
public function handleRemove(int $redirectId) : void
    {
        if ($this->presenter->isAjax() && $this->presenter->user->isAllowed(OnPageAuthorizator::RES_REDIRECT_REMOVE))
        {
            $redirect = $this->onPageRepository->findOneRedirectById($redirectId);

            if ($redirect)
            {
                $this->onPageManager->removeRedirect($redirect);

                $this->presenter->notificationAjax(
                    'URL odstraněna',
                    'URL pro přesměrování byla úspěšně odstraněna.',
                    'info',
                    FALSE
                );

                $this->presenter->handleModalToggle('hide', '#wakers_onpage_redirect_remove_modal', FALSE);

                $this->onRemove();
            }
        }
    }
547494
protected function _setRedirectUrl(ServerRequest $request)
    {
        $request->getSession()->delete('SocialAuth.redirectUrl');

        $redirectUrl = $request->getQuery(static::QUERY_STRING_REDIRECT);
        if (empty($redirectUrl)
            || substr($redirectUrl, 0, 1) !== '/'
            || substr($redirectUrl, 0, 2) === '//'
        ) {
            return;
        }

        $request->getSession()->write('SocialAuth.redirectUrl', $redirectUrl);
    }
299282
public <T extends AbstractPutObjectRequest> T withRedirectLocation(
            String redirectLocation) {
        this.redirectLocation = redirectLocation;
        @SuppressWarnings("unchecked") T t = (T)this;
        return t;
    }
1238048
protected function RedirectAfterEvent($iRequestRedirectNodeId)
    {
        if (is_null($iRequestRedirectNodeId)) {
            $this->RedirectToCallingPage();
        } else {
            $checkoutSystemPage = $this->getSystemPageService()->getSystemPage('checkout');
            if (null !== $checkoutSystemPage && $checkoutSystemPage->fieldCmsTreeId == $iRequestRedirectNodeId) {
                $this->JumpToBasketPage();
            } else {
                $oNode = new TdbCmsTree();
                if ($oNode->Load($iRequestRedirectNodeId)) {
                    $url = $this->getTreeService()->getLinkToPageForTreeRelative($oNode);
                    $this->getRedirect()->redirect($url);
                } else {
                    $this->RedirectToCallingPage();
                }
            }
        }
    }
666669
public function postAction(Request $request)
    {
        $data = $request->request->all();

        $serializer = $this->get('serializer');
        $redirectRoute = $serializer->deserialize(
            json_encode($data),
            $this->getParameter('sulu.model.redirect_route.class'),
            'json'
        );

        $this->getRedirectRouteManager()->save($redirectRoute);
        $this->get('doctrine.orm.entity_manager')->flush();

        return $this->handleView($this->view($redirectRoute));
    }
969339
public function setRedirectView($redirectView)
    {
        if (!is_file($redirectView)) {
            throw new \RuntimeException(sprintf('Redirect view file "%s" not found', $redirectView));
        }
        $this->redirectView = $redirectView;
        return $this;
    }
791238
private function mustRedirect(ServerRequestInterface $request): bool
    {
        if ($this->redirect === false) {
            return false;
        }

        return !$this->checkHttpsForward || (
            $request->getHeaderLine('X-Forwarded-Proto') !== 'https' &&
            $request->getHeaderLine('X-Forwarded-Port') !== '443'
        );
    }
140954
protected function forceRedirect($redirectTo = '')
    {
        if (empty($redirectTo))
        {
            $this->runDefaultBehavior();
        }

        Craft::$app->response->redirect($redirectTo, $this->settings->redirectStatusCode);
    }
1171591
public function redirectToRouteAction(Request $request, $route, $permanent = false)
    {
        if ('' === $route) {
            throw new HttpException($permanent ? 410 : 404);
        }

        $attributes = array_merge($request->attributes->get('_route_params'), $request->query->all());
        unset($attributes['route'], $attributes['permanent']);

        return new RedirectResponse(
            $this->container->get('router')->generate($route, $attributes, UrlGeneratorInterface::ABSOLUTE_URL),
            $permanent ? 301 : 302,
            ['Cache-Control' => 'private']
        );
    }
677455
public function get(RequestInterface $request, $retryWithUrlEncodingDisabled = null)
    {
        $configuration = $this->getConfiguration();

        if (!$configuration->getAllowUnknownResourceTypes()) {
            $headRequest = clone $request;
            $headRequest->withMethod('HEAD');

            $this->preVerifyContentType($headRequest);
        }

        try {
            $response = $configuration->getHttpClient()->send($request);
        } catch (BadResponseException $badResponseException) {
            if (is_null($retryWithUrlEncodingDisabled) && $configuration->getRetryWithUrlEncodingDisabled()) {
                $retryWithUrlEncodingDisabled = true;
            }

            if ($retryWithUrlEncodingDisabled) {
                return $this->get($this->deEncodeRequestUrl($request), false);
            }

            $response = $badResponseException->getResponse();
        }

        if ($this->isBadResponse($response)) {
            throw new WebResourceException($response, $request);
        }

        if ($this->isInformationalResponse($response)) {
            throw new WebResourceException($response, $request);
        }

        if ($this->isRedirectResponse($response)) {
            // Shouldn't happen, HTTP client should have the redirect handler
            // enabled, redirects should be followed
            throw new WebResourceException($response, $request);
        }

        $contentType = $this->getContentTypeFromResponse($response);
        $contentTypeSubtypeString = $contentType->getTypeSubtypeString();
        $hasMappedWebResourceClassName = $configuration->hasMappedWebResourceClassName($contentTypeSubtypeString);

        if (!$hasMappedWebResourceClassName && !$configuration->getAllowUnknownResourceTypes()) {
            throw new InvalidContentTypeException($contentType, $response, $request);
        }

        $webResourceClassName = $configuration->getWebResourceClassName($contentTypeSubtypeString);

        return new $webResourceClassName($response, $request->getUri());
    }
621612
protected function _redirect($url, $httpStatusCode = 302)
    {
        if (empty($url)) throw new ControllerRedirectEmptyUrlException('Cannot redirect to an empty url.');

        header('location:' . $url, true, $httpStatusCode);
        exit;
    }
136248
public function setRedirectUri($redirect_uri)
    {
        // $redirect_uri = trim(urldecode($redirect_uri));
        $redirect_uri = trim($redirect_uri);
        if (filter_var($redirect_uri, FILTER_VALIDATE_URL) === false) {
            throw new Exception('$redirect_uri无效');
        }
        $this->_redirect_uri = urlencode($redirect_uri);
    }
466775
public function setLastRequestTime(RequestInterface $request)
    {
        $route = $this->getRoute($request);
        $key   = $this->getKey($route.'.lastRequest');

        $this->redis->setex($key, static::MAX_TTL, $this->getRequestTime($request));
    }
550545
private function setRedirectUrl(
        RequestInterface $request,
        ResponseInterface $response,
        array $protocols
    ) {
        $location = $response->getHeader('Location');
        $location = Url::fromString($location);

        // Combine location with the original URL if it is not absolute.
        if (!$location->isAbsolute()) {
            $originalUrl = Url::fromString($request->getUrl());
            // Remove query string parameters and just take what is present on
            // the redirect Location header
            $originalUrl->getQuery()->clear();
            $location = $originalUrl->combine($location);
        }

        // Ensure that the redirect URL is allowed based on the protocols.
        if (!in_array($location->getScheme(), $protocols)) {
            throw new BadResponseException(
                sprintf(
                    'Redirect URL, %s, does not use one of the allowed redirect protocols: %s',
                    $location,
                    implode(', ', $protocols)
                ),
                $request,
                $response
            );
        }

        $request->setUrl($location);
    }
202243
protected function buildRedirectRequest(RequestInterface $request, UriInterface $uri, $statusCode)
    {
        $request = $request->withUri($uri);

        if (false !== $this->redirectCodes[$statusCode]['switch'] && !in_array($request->getMethod(), $this->redirectCodes[$statusCode]['switch']['unless'])) {
            $request = $request->withMethod($this->redirectCodes[$statusCode]['switch']['to']);
        }

        if (is_array($this->preserveHeader)) {
            $headers = array_keys($request->getHeaders());

            foreach ($headers as $name) {
                if (!in_array($name, $this->preserveHeader)) {
                    $request = $request->withoutHeader($name);
                }
            }
        }

        return $request;
    }