Skip to content

Commit 1105db3

Browse files
authored
Add Option to Disable SSL Verification for cURL Requests (#81)
1 parent d9cde8c commit 1105db3

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ Example config:
185185
'timeout' => 3,
186186
// the token must match 'upload.token' config in XHGui
187187
'token' => 'token',
188+
// verify option to disable ssl verification, defaults to true if unspecified.
189+
'verify' => true,
188190
),
189191
```
190192

src/Saver/UploadSaver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ final class UploadSaver implements SaverInterface
1010
private $url;
1111
/** @var int */
1212
private $timeout;
13+
/** @var bool */
14+
private $verify;
1315

14-
public function __construct($url, $token, $timeout)
16+
public function __construct($url, $token, $timeout, $verify)
1517
{
1618
$this->url = $url;
1719
if ($token) {
1820
$this->url .= '?&token=' . $token;
1921
}
2022

2123
$this->timeout = $timeout;
24+
$this->verify = $verify;
2225
}
2326

2427
public function isSupported()
@@ -64,6 +67,7 @@ private function submit($url, $payload)
6467
CURLOPT_FOLLOWLOCATION => 1,
6568
CURLOPT_HTTPHEADER => $headers,
6669
CURLOPT_TIMEOUT => $this->timeout,
70+
CURLOPT_SSL_VERIFYPEER => $this->verify,
6771
));
6872
if (!$res) {
6973
$error = curl_errno($ch) ? curl_error($ch) : '';

src/SaverFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ public static function create($saveHandler, Config $config)
3535
'url' => null,
3636
'token' => null,
3737
'timeout' => 3,
38+
'verify' => true,
3839
);
3940
$userConfig = isset($config['save.handler.upload']) && is_array($config['save.handler.upload']) ? $config['save.handler.upload'] : array();
4041
$saverConfig = array_merge($defaultConfig, $userConfig);
41-
$saver = new Saver\UploadSaver($saverConfig['url'] ?: $saverConfig['uri'], $saverConfig['token'], $saverConfig['timeout']);
42+
$saver = new Saver\UploadSaver(
43+
$saverConfig['url'] ?: $saverConfig['uri'],
44+
$saverConfig['token'],
45+
$saverConfig['timeout'],
46+
$saverConfig['verify']
47+
);
4248
break;
4349

4450
case Profiler::SAVER_STACK:

0 commit comments

Comments
 (0)