Skip to content

Commit 9d69bb6

Browse files
committed
Added possibility to enable accepting certificates from a file
1 parent ff84d8b commit 9d69bb6

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

docs/en/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ $httpRequest = HttpRequest::from('https://www.example.com/', HttpMethod::GET, [
125125
]);
126126
```
127127

128+
Option `verify` can be set by boolean value or by specifying path to accepted certificate file.
129+
130+
```php
131+
$httpRequest = HttpRequest::from('https://www.example.com/', HttpMethod::GET, [
132+
'verify' => false,
133+
]);
134+
```
135+
136+
```php
137+
$httpRequest = HttpRequest::from('https://www.example.com/', HttpMethod::GET, [
138+
'verify' => 'path/to/some/accepted/certificate.crt',
139+
]);
140+
```
141+
128142
## Redirects
129143

130144

src/Fapi/HttpClient/GuzzleHttpClient.php

100644100755
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,17 @@ private function processOptions(RequestInterface $request): array
104104
$options['connect_timeout'] = (int) ($headerLine !== '' ? $headerLine : 5);
105105
}
106106

107-
if ($request->hasHeader('verify') && !(bool) $request->getHeaderLine('verify')) {
108-
$options['verify'] = false;
107+
if ($request->hasHeader('verify')) {
108+
$headerLine = $request->getHeaderLine('verify');
109+
110+
$options['verify'] = match($headerLine) {
111+
'false', '' => false,
112+
'true', '1' => true,
113+
default => $headerLine,
114+
};
109115
}
110116

117+
111118
if ($request->hasHeader('cert')) {
112119
$options['cert'] = $request->getHeaderLine('cert');
113120
}

src/Fapi/HttpClient/HttpRequest.php

100644100755
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ private static function preProcessHeaders(array $options, StreamInterface|string
108108
if (isset($options['verify'])) {
109109
$value = $options['verify'];
110110
self::validateVerify($value);
111-
$data['verify'] = (bool) $value;
111+
if (is_bool($value)) {
112+
$value = $value ? 'true' : 'false';
113+
}
114+
$data['verify'] = $value;
112115
}
113116

114117
if (isset($options['cert'])) {
@@ -211,8 +214,8 @@ private static function validateConnectTimeoutOption(mixed $connectTimeout): voi
211214

212215
private static function validateVerify(mixed $verify): void
213216
{
214-
if (!is_bool($verify)) {
215-
throw new InvalidArgumentException('Option verify must be an bool.');
217+
if (!(is_bool($verify) || (is_string($verify) && file_exists($verify)))) {
218+
throw new InvalidArgumentException('Option verify must be an bool or a string path to file, '.$verify.' given.');
216219
}
217220
}
218221

0 commit comments

Comments
 (0)