handle redirection loop #93

Open
KernelFolla opened this Issue Jan 18, 2013 · 1 comment

Projects

None yet

2 participants

@KernelFolla

browserkit redirection don't handle a loop of redirects, i can only disable or enable the redirection.

So i have this loop and can't catch it:

Symfony\Component\BrowserKit\Client->request( ) ..\Client.php:423
Symfony\Component\BrowserKit\Client->followRedirect( )  ..\Client.php:274

for my problem, i've solved it catching the loop in createResponse

class MyClient extends Client{
    const MAX_REDIRECTS = 5;

    public $redirectCount = 0;

    public function request($x, $y){
        return parent::request($x,$y);
    }

    protected function createResponse(GuzzleResponse $response)
    {
        $this->checkRedirectionLoop($response->getStatusCode());
        return parent::createResponse($response);
    }

    protected function checkRedirectionLoop($statusCode){
        $isRedirect = $statusCode == 301 || $statusCode == 302;
        if($isRedirect){
            $this->redirectCount++;
            if($this->redirectCount >= self::MAX_REDIRECTS){
                $this->redirectCount = 0;
                throw new Exception('intercepted loop of redirects');
            }
        }else{
            $this->redirectCount = 0;
        }
    }
}
@csev

I believe this is old and has been fixed. I have a recent version and solve the problem this way:

$client = new Client();
$client->setMaxRedirects(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment