protected function fetchWhileRedirected($url, $encoding)
    {
        $redirects = 0;
        do {
            $response = $this->fetch($url, $encoding);
            if ($response->isError()) {
                return $response;
            }
            $headers = $response->getHeaders();
            if ($this->cookies_enabled) {
                $headers->writeCookiesToJar($this->cookie_jar, $url);
            }
            if (! $headers->isRedirect()) {
                break;
            }
            $location = new SimpleUrl($headers->getLocation());
            $url      = $location->makeAbsolute($url);
            $encoding = new SimpleGetEncoding();
        } while (! $this->isTooManyRedirects(++$redirects));

        return $response;
    }
protected function fetchWhileRedirected($url, $encoding)
    {
        $redirects = 0;
        do {
            $response = $this->fetch($url, $encoding);
            if ($response->isError()) {
                return $response;
            }
            $headers = $response->getHeaders();
            if ($this->cookies_enabled) {
                $headers->writeCookiesToJar($this->cookie_jar, $url);
            }
            if (! $headers->isRedirect()) {
                break;
            }
            $location = new SimpleUrl($headers->getLocation());
            $url      = $location->makeAbsolute($url);
            $encoding = new SimpleGetEncoding();
        } while (! $this->isTooManyRedirects(++$redirects));

        return $response;
    }
protected function fetchWhileRedirected ( $ url , $ encoding ) { $ redirects = 0 ; do { $ response = $ this -> fetch ( $ url , $ encoding ) ; if ( $ response -> isError ( ) ) { return $ response ; } $ headers = $ response -> getHeaders ( ) ; if ( $ this -> cookies_enabled ) { $ headers -> writeCookiesToJar ( $ this -> cookie_jar , $ url ) ; } if ( ! $ headers -> isRedirect ( ) ) { break ; } $ location = new SimpleUrl ( $ headers -> getLocation ( ) ) ; $ url = $ location -> makeAbsolute ( $ url ) ; $ encoding = new SimpleGetEncoding ( ) ; } while ( ! $ this -> isTooManyRedirects ( ++ $ redirects ) ) ; return $ response ; }
Fetches the page until no longer redirected or until the redirect limit runs out.

@param SimpleUrl $url                  Target to fetch.
@param SimpelFormEncoding $encoding    Additional parameters for request.

@return SimpleHttpResponse             Hopefully the target page.
Fetches the page until no longer redirected or until the redirect limit runs out .