private function createUri(ResponseInterface $response, RequestInterface $request)
    {
        if ($this->redirectCodes[$response->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$response->hasHeader('Location'))) {
            throw new MultipleRedirectionException('Cannot choose a redirection', $request, $response);
        }

        if (!$response->hasHeader('Location')) {
            throw new HttpException('Redirect status code, but no location header present in the response', $request, $response);
        }

        $location = $response->getHeaderLine('Location');
        $parsedLocation = parse_url($location);

        if (false === $parsedLocation) {
            throw new HttpException(sprintf('Location %s could not be parsed', $location), $request, $response);
        }

        $uri = $request->getUri();

        if (array_key_exists('scheme', $parsedLocation)) {
            $uri = $uri->withScheme($parsedLocation['scheme']);
        }

        if (array_key_exists('host', $parsedLocation)) {
            $uri = $uri->withHost($parsedLocation['host']);
        }

        if (array_key_exists('port', $parsedLocation)) {
            $uri = $uri->withPort($parsedLocation['port']);
        }

        if (array_key_exists('path', $parsedLocation)) {
            $uri = $uri->withPath($parsedLocation['path']);
        }

        if (array_key_exists('query', $parsedLocation)) {
            $uri = $uri->withQuery($parsedLocation['query']);
        } else {
            $uri = $uri->withQuery('');
        }

        if (array_key_exists('fragment', $parsedLocation)) {
            $uri = $uri->withFragment($parsedLocation['fragment']);
        } else {
            $uri = $uri->withFragment('');
        }

        return $uri;
    }
private function createUri(ResponseInterface $response, RequestInterface $request)
    {
        if ($this->redirectCodes[$response->getStatusCode()]['multiple'] && (!$this->useDefaultForMultiple || !$response->hasHeader('Location'))) {
            throw new MultipleRedirectionException('Cannot choose a redirection', $request, $response);
        }

        if (!$response->hasHeader('Location')) {
            throw new HttpException('Redirect status code, but no location header present in the response', $request, $response);
        }

        $location = $response->getHeaderLine('Location');
        $parsedLocation = parse_url($location);

        if (false === $parsedLocation) {
            throw new HttpException(sprintf('Location %s could not be parsed', $location), $request, $response);
        }

        $uri = $request->getUri();

        if (array_key_exists('scheme', $parsedLocation)) {
            $uri = $uri->withScheme($parsedLocation['scheme']);
        }

        if (array_key_exists('host', $parsedLocation)) {
            $uri = $uri->withHost($parsedLocation['host']);
        }

        if (array_key_exists('port', $parsedLocation)) {
            $uri = $uri->withPort($parsedLocation['port']);
        }

        if (array_key_exists('path', $parsedLocation)) {
            $uri = $uri->withPath($parsedLocation['path']);
        }

        if (array_key_exists('query', $parsedLocation)) {
            $uri = $uri->withQuery($parsedLocation['query']);
        } else {
            $uri = $uri->withQuery('');
        }

        if (array_key_exists('fragment', $parsedLocation)) {
            $uri = $uri->withFragment($parsedLocation['fragment']);
        } else {
            $uri = $uri->withFragment('');
        }

        return $uri;
    }
private function createUri ( ResponseInterface $ response , RequestInterface $ request ) { if ( $ this -> redirectCodes [ $ response -> getStatusCode ( ) ] [ 'multiple' ] && ( ! $ this -> useDefaultForMultiple || ! $ response -> hasHeader ( 'Location' ) ) ) { throw new MultipleRedirectionException ( 'Cannot choose a redirection' , $ request , $ response ) ; } if ( ! $ response -> hasHeader ( 'Location' ) ) { throw new HttpException ( 'Redirect status code, but no location header present in the response' , $ request , $ response ) ; } $ location = $ response -> getHeaderLine ( 'Location' ) ; $ parsedLocation = parse_url ( $ location ) ; if ( false === $ parsedLocation ) { throw new HttpException ( sprintf ( 'Location %s could not be parsed' , $ location ) , $ request , $ response ) ; } $ uri = $ request -> getUri ( ) ; if ( array_key_exists ( 'scheme' , $ parsedLocation ) ) { $ uri = $ uri -> withScheme ( $ parsedLocation [ 'scheme' ] ) ; } if ( array_key_exists ( 'host' , $ parsedLocation ) ) { $ uri = $ uri -> withHost ( $ parsedLocation [ 'host' ] ) ; } if ( array_key_exists ( 'port' , $ parsedLocation ) ) { $ uri = $ uri -> withPort ( $ parsedLocation [ 'port' ] ) ; } if ( array_key_exists ( 'path' , $ parsedLocation ) ) { $ uri = $ uri -> withPath ( $ parsedLocation [ 'path' ] ) ; } if ( array_key_exists ( 'query' , $ parsedLocation ) ) { $ uri = $ uri -> withQuery ( $ parsedLocation [ 'query' ] ) ; } else { $ uri = $ uri -> withQuery ( '' ) ; } if ( array_key_exists ( 'fragment' , $ parsedLocation ) ) { $ uri = $ uri -> withFragment ( $ parsedLocation [ 'fragment' ] ) ; } else { $ uri = $ uri -> withFragment ( '' ) ; } return $ uri ; }
Creates a new Uri from the old request and the location header.

@param ResponseInterface $response The redirect response
@param RequestInterface  $request  The original request

@throws HttpException                If location header is not usable (missing or incorrect)
@throws MultipleRedirectionException If a 300 status code is received and default location cannot be resolved (doesn't use the location header or not present)

@return UriInterface
Creates a new Uri from the old request and the location header .