protected function handleRedirect(
        HTTP_Request2 $request, HTTP_Request2_Response $response
    ) {
        if (is_null($this->redirectCountdown)) {
            $this->redirectCountdown = $request->getConfig('max_redirects');
        }
        if (0 == $this->redirectCountdown) {
            $this->redirectCountdown = null;
            // Copying cURL behaviour
            throw new HTTP_Request2_MessageException(
                'Maximum (' . $request->getConfig('max_redirects') . ') redirects followed',
                HTTP_Request2_Exception::TOO_MANY_REDIRECTS
            );
        }
        $redirectUrl = new Net_URL2(
            $response->getHeader('location'),
            array(Net_URL2::OPTION_USE_BRACKETS => $request->getConfig('use_brackets'))
        );
        // refuse non-HTTP redirect
        if ($redirectUrl->isAbsolute()
            && !in_array($redirectUrl->getScheme(), array('http', 'https'))
        ) {
            $this->redirectCountdown = null;
            throw new HTTP_Request2_MessageException(
                'Refusing to redirect to a non-HTTP URL ' . $redirectUrl->__toString(),
                HTTP_Request2_Exception::NON_HTTP_REDIRECT
            );
        }
        // Theoretically URL should be absolute (see http://tools.ietf.org/html/rfc2616#section-14.30),
        // but in practice it is often not
        if (!$redirectUrl->isAbsolute()) {
            $redirectUrl = $request->getUrl()->resolve($redirectUrl);
        }
        $redirect = clone $request;
        $redirect->setUrl($redirectUrl);
        if (303 == $response->getStatus()
            || (!$request->getConfig('strict_redirects')
                && in_array($response->getStatus(), array(301, 302)))
        ) {
            $redirect->setMethod(HTTP_Request2::METHOD_GET);
            $redirect->setBody('');
        }

        if (0 < $this->redirectCountdown) {
            $this->redirectCountdown--;
        }
        return $this->sendRequest($redirect);
    }
protected function handleRedirect(
        HTTP_Request2 $request, HTTP_Request2_Response $response
    ) {
        if (is_null($this->redirectCountdown)) {
            $this->redirectCountdown = $request->getConfig('max_redirects');
        }
        if (0 == $this->redirectCountdown) {
            $this->redirectCountdown = null;
            // Copying cURL behaviour
            throw new HTTP_Request2_MessageException(
                'Maximum (' . $request->getConfig('max_redirects') . ') redirects followed',
                HTTP_Request2_Exception::TOO_MANY_REDIRECTS
            );
        }
        $redirectUrl = new Net_URL2(
            $response->getHeader('location'),
            array(Net_URL2::OPTION_USE_BRACKETS => $request->getConfig('use_brackets'))
        );
        // refuse non-HTTP redirect
        if ($redirectUrl->isAbsolute()
            && !in_array($redirectUrl->getScheme(), array('http', 'https'))
        ) {
            $this->redirectCountdown = null;
            throw new HTTP_Request2_MessageException(
                'Refusing to redirect to a non-HTTP URL ' . $redirectUrl->__toString(),
                HTTP_Request2_Exception::NON_HTTP_REDIRECT
            );
        }
        // Theoretically URL should be absolute (see http://tools.ietf.org/html/rfc2616#section-14.30),
        // but in practice it is often not
        if (!$redirectUrl->isAbsolute()) {
            $redirectUrl = $request->getUrl()->resolve($redirectUrl);
        }
        $redirect = clone $request;
        $redirect->setUrl($redirectUrl);
        if (303 == $response->getStatus()
            || (!$request->getConfig('strict_redirects')
                && in_array($response->getStatus(), array(301, 302)))
        ) {
            $redirect->setMethod(HTTP_Request2::METHOD_GET);
            $redirect->setBody('');
        }

        if (0 < $this->redirectCountdown) {
            $this->redirectCountdown--;
        }
        return $this->sendRequest($redirect);
    }
protected function handleRedirect ( HTTP_Request2 $ request , HTTP_Request2_Response $ response ) { if ( is_null ( $ this -> redirectCountdown ) ) { $ this -> redirectCountdown = $ request -> getConfig ( 'max_redirects' ) ; } if ( 0 == $ this -> redirectCountdown ) { $ this -> redirectCountdown = null ; // Copying cURL behaviour
 throw new HTTP_Request2_MessageException ( 'Maximum (' . $ request -> getConfig ( 'max_redirects' ) . ') redirects followed' , HTTP_Request2_Exception :: TOO_MANY_REDIRECTS ) ; } $ redirectUrl = new Net_URL2 ( $ response -> getHeader ( 'location' ) , array ( Net_URL2 :: OPTION_USE_BRACKETS => $ request -> getConfig ( 'use_brackets' ) ) ) ; // refuse non-HTTP redirect
 if ( $ redirectUrl -> isAbsolute ( ) && ! in_array ( $ redirectUrl -> getScheme ( ) , array ( 'http' , 'https' ) ) ) { $ this -> redirectCountdown = null ; throw new HTTP_Request2_MessageException ( 'Refusing to redirect to a non-HTTP URL ' . $ redirectUrl -> __toString ( ) , HTTP_Request2_Exception :: NON_HTTP_REDIRECT ) ; } // Theoretically URL should be absolute (see http://tools.ietf.org/html/rfc2616#section-14.30),
 // but in practice it is often not
 if ( ! $ redirectUrl -> isAbsolute ( ) ) { $ redirectUrl = $ request -> getUrl ( ) -> resolve ( $ redirectUrl ) ; } $ redirect = clone $ request ; $ redirect -> setUrl ( $ redirectUrl ) ; if ( 303 == $ response -> getStatus ( ) || ( ! $ request -> getConfig ( 'strict_redirects' ) && in_array ( $ response -> getStatus ( ) , array ( 301 , 302 ) ) ) ) { $ redirect -> setMethod ( HTTP_Request2 :: METHOD_GET ) ; $ redirect -> setBody ( '' ) ; } if ( 0 < $ this -> redirectCountdown ) { $ this -> redirectCountdown -- ; } return $ this -> sendRequest ( $ redirect ) ; }
Handles HTTP redirection

This method will throw an Exception if redirect to a non-HTTP(S) location
is attempted, also if number of redirects performed already is equal to
'max_redirects' configuration parameter.

@param HTTP_Request2          $request  Original request
@param HTTP_Request2_Response $response Response containing redirect

@return   HTTP_Request2_Response      Response from a new location
@throws   HTTP_Request2_Exception
Handles HTTP redirection