Skip to content

Commit f721b90

Browse files
authored
Merge pull request #474 from stevecoug/master
Allow settings to override many cURL options
2 parents 0b545ec + 7fac0ac commit f721b90

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,14 @@ use Embed\Http\CurlClient;
315315
$client = new CurlClient();
316316
$client->setSettings([
317317
'cookies_path' => $cookies_path,
318-
'ignored_errors' => [18]
318+
'ignored_errors' => [18],
319+
'max_redirs' => 3, // see CURLOPT_MAXREDIRS
320+
'connect_timeout' => 2, // see CURLOPT_CONNECTTIMEOUT
321+
'timeout' => 2, // see CURLOPT_TIMEOUT
322+
'ssl_verify_host' => 2, // see CURLOPT_SSL_VERIFYHOST
323+
'ssl_verify_peer' => 1, // see CURLOPT_SSL_VERIFYPEER
324+
'follow_location' => true, // see CURLOPT_FOLLOWLOCATION
325+
'user_agent' => 'Mozilla', // see CURLOPT_USERAGENT
319326
]);
320327

321328
$embed = new Embed(new Crawler($client));

src/Http/CurlDispatcher.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ private function __construct(array $settings, RequestInterface $request)
8787
curl_setopt_array($this->curl, [
8888
CURLOPT_HTTPHEADER => $this->getRequestHeaders(),
8989
CURLOPT_POST => strtoupper($request->getMethod()) === 'POST',
90-
CURLOPT_MAXREDIRS => 10,
91-
CURLOPT_CONNECTTIMEOUT => 10,
92-
CURLOPT_TIMEOUT => 10,
90+
CURLOPT_MAXREDIRS => $settings['max_redirs'] ?? 10,
91+
CURLOPT_CONNECTTIMEOUT => $settings['connect_timeout'] ?? 10,
92+
CURLOPT_TIMEOUT => $settings['timeout'] ?? 10,
9393
CURLOPT_RETURNTRANSFER => true,
94-
CURLOPT_SSL_VERIFYHOST => 0,
95-
CURLOPT_SSL_VERIFYPEER => false,
94+
CURLOPT_SSL_VERIFYHOST => $settings['ssl_verify_host'] ?? 0,
95+
CURLOPT_SSL_VERIFYPEER => $settings['ssl_verify_peer'] ?? false,
9696
CURLOPT_ENCODING => '',
9797
CURLOPT_CAINFO => CaBundle::getSystemCaRootBundlePath(),
9898
CURLOPT_AUTOREFERER => true,
99-
CURLOPT_FOLLOWLOCATION => true,
99+
CURLOPT_FOLLOWLOCATION => $settings['follow_location'] ?? true,
100100
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
101-
CURLOPT_USERAGENT => $request->getHeaderLine('User-Agent'),
101+
CURLOPT_USERAGENT => $settings['user_agent'] ?? $request->getHeaderLine('User-Agent'),
102102
CURLOPT_COOKIEJAR => $cookies,
103103
CURLOPT_COOKIEFILE => $cookies,
104104
CURLOPT_HEADERFUNCTION => [$this, 'writeHeader'],

0 commit comments

Comments
 (0)