Skip to content

Commit

Permalink
Honor user provided Guzzle opts with Pool (spatie#48)
Browse files Browse the repository at this point in the history
* Fix Guzzle config bug

With this change the user provided Guzzle options will be honored when setting up the Pool.

* Fix whitespace

* Fix issue found with styleCI
  • Loading branch information
mallardduck authored and freekmurze committed Dec 30, 2016
1 parent 4b8516b commit dbade2e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ class Crawler
*/
public static function create(array $clientOptions = [])
{
$client = new Client($clientOptions ?? [

$hasClientOpts = (bool) count($clientOptions);
$client = new Client($hasClientOpts ? $clientOptions : [
RequestOptions::COOKIES => true,
RequestOptions::CONNECT_TIMEOUT => 10,
RequestOptions::TIMEOUT => 10,
RequestOptions::ALLOW_REDIRECTS => false,
]);

return new static($client);
Expand Down Expand Up @@ -119,11 +122,7 @@ protected function startCrawlingQueue()
while ($this->crawlQueue->hasPendingUrls()) {
$pool = new Pool($this->client, $this->getCrawlRequests(), [
'concurrency' => $this->concurrency,
'options' => [
RequestOptions::CONNECT_TIMEOUT => 10,
RequestOptions::TIMEOUT => 10,
RequestOptions::ALLOW_REDIRECTS => false,
],
'options' => $this->client->getConfig(),
'fulfilled' => function (ResponseInterface $response, int $index) {
$this->handleResponse($response, $index);

Expand Down

0 comments on commit dbade2e

Please sign in to comment.