FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Goutte setup allow_redirects=false for Guzzle, while inherits $followRedirects=true from BrowserKit #378

Open karser opened 5 years ago

karser commented 5 years ago

Hello.

Throughout the Goutte client, the allow_redirects is set to false. I tend to agree with this because I use it for tests.

The issue is that in the abstract BrowserKit Client, which the Goutte client extends from, the variable followRedirects is set to true. So that forms submission automatically follows location.

abstract class Client
    protected $followRedirects = true;

As a workaround, this option has to be set manually:

$client->followRedirects(false);
$client->submitForm('Click me', [])

The solution is to override the default value of $followRedirects from the BrowserKit Client:

namespace Goutte;

class Client extends BaseClient {
    protected $followRedirects = false;

This change fixes inconsistency, but also introduces a BC break though.