-
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathGuzzleHttpHandler.php
More file actions
639 lines (565 loc) · 24.9 KB
/
GuzzleHttpHandler.php
File metadata and controls
639 lines (565 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpClient;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Promise\Utils as PromiseUtils;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use GuzzleHttp\Psr7\Utils as Psr7Utils;
use GuzzleHttp\TransferStats;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface as SymfonyResponseInterface;
/**
* A Guzzle handler that uses Symfony's HttpClientInterface as its transport.
*
* This lets SDKs tightly coupled to Guzzle benefit from Symfony HttpClient's
* features (e.g. retry logic, tracing, scoping, mocking) by plugging this
* handler into a Guzzle client:
*
* $handler = new GuzzleHttpHandler(HttpClient::create());
* $guzzle = new \GuzzleHttp\Client(['handler' => $handler]);
*
* The handler is truly asynchronous: __invoke() returns a *pending* Promise
* immediately without performing any I/O. The actual work is driven by
* Symfony's HttpClientInterface::stream(), which multiplexes all in-flight
* requests together - the same approach CurlMultiHandler takes with
* curl_multi_*. Waiting on any single promise drives the whole pool so
* concurrent requests benefit from parallelism automatically.
*
* Guzzle request options are mapped to their Symfony equivalents as faithfully
* as possible; unsupported options are silently ignored so that existing SDK
* option sets do not cause errors.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
final class GuzzleHttpHandler
{
private readonly HttpClientInterface $client;
/**
* Maps each Symfony response (key) to a 3-tuple:
* [Psr7 RequestInterface, Guzzle options array, Guzzle Promise]
*
* @var \SplObjectStorage<SymfonyResponseInterface, array{0: RequestInterface, 1: array, 2: Promise}>
*/
private readonly \SplObjectStorage $pending;
/**
* PSR-7 response created eagerly on the first chunk so that the same
* instance is passed to on_headers and later resolved by the promise.
*
* @var \SplObjectStorage<SymfonyResponseInterface, ResponseInterface>
*/
private readonly \SplObjectStorage $psr7Responses;
private readonly bool $autoUpgradeHttpVersion;
public function __construct(?HttpClientInterface $client = null, bool $autoUpgradeHttpVersion = true)
{
$this->client = $client ?? HttpClient::create();
$this->autoUpgradeHttpVersion = $autoUpgradeHttpVersion;
$this->pending = new \SplObjectStorage();
$this->psr7Responses = new \SplObjectStorage();
}
/**
* Returns a *pending* Promise - no I/O is performed here.
*
* The wait function passed to the Promise drives Symfony's stream() loop,
* which resolves all currently queued requests concurrently.
*/
public function __invoke(RequestInterface $request, array $options): PromiseInterface
{
$symfonyOptions = $this->buildSymfonyOptions($request, $options);
try {
$symfonyResponse = $this->client->request($request->getMethod(), (string) $request->getUri(), $symfonyOptions);
} catch (\Exception $e) {
// Option validation errors surface here synchronously.
$p = new Promise();
$p->reject($e);
return $p;
}
$promise = new Promise(
function () use ($symfonyResponse): void {
$this->streamPending(null, $symfonyResponse);
},
function () use ($symfonyResponse): void {
unset($this->pending[$symfonyResponse], $this->psr7Responses[$symfonyResponse]);
$symfonyResponse->cancel();
},
);
$this->pending[$symfonyResponse] = [$request, $options, $promise];
if (isset($options['delay'])) {
$pause = $symfonyResponse->getInfo('pause_handler');
if (\is_callable($pause)) {
$pause($options['delay'] / 1000.0);
} else {
usleep((int) ($options['delay'] * 1000));
}
}
return $promise;
}
/**
* Ticks the event loop: processes available I/O and runs queued tasks.
*
* @param float $timeout Maximum time in seconds to wait for network activity (0 = non-blocking)
*/
public function tick(float $timeout = 1.0): void
{
$queue = PromiseUtils::queue();
// Push streaming work onto the Guzzle task queue so that .then()
// callbacks and other queued tasks get cooperative scheduling.
$queue->add(fn () => $this->streamPending($timeout, true));
$queue->run();
}
/**
* Runs until all outstanding connections have completed.
*/
public function execute(): void
{
while ($this->pending->count()) {
$this->streamPending(null, false);
}
}
/**
* Performs one pass of streaming I/O over all pending responses.
*
* @param float|null $timeout Idle timeout passed to stream(); 0 for non-blocking, null for default
*/
private function streamPending(?float $timeout, bool|SymfonyResponseInterface $breakAfter): void
{
if (!$this->pending->count()) {
return;
}
$queue = PromiseUtils::queue();
$responses = [];
foreach ($this->pending as $r) {
$responses[] = $r;
}
foreach ($this->client->stream($responses, $timeout) as $response => $chunk) {
try {
if ($chunk->isTimeout()) {
continue;
}
if ($chunk->isFirst()) {
// Deactivate 4xx/5xx exception throwing for this response;
// Guzzle's http_errors middleware handles that layer.
$response->getStatusCode();
[, $guzzleOpts] = $this->pending[$response] ?? [null, []];
$sink = $guzzleOpts['sink'] ?? null;
$body = Psr7Utils::streamFor(\is_string($sink) ? fopen($sink, 'w+') : ($sink ?? fopen('php://temp', 'r+')));
if (600 <= $response->getStatusCode()) {
$psrResponse = new GuzzleResponse(567, $response->getHeaders(false), $body);
(new \ReflectionProperty($psrResponse, 'statusCode'))->setValue($psrResponse, $response->getStatusCode());
} else {
$psrResponse = new GuzzleResponse($response->getStatusCode(), $response->getHeaders(false), $body);
}
$this->psr7Responses[$response] = $psrResponse;
if (isset($guzzleOpts['on_headers'])) {
try {
($guzzleOpts['on_headers'])($psrResponse);
} catch (\Throwable $e) {
[$guzzleRequest, , $promise] = $this->pending[$response];
unset($this->pending[$response], $this->psr7Responses[$response]);
$this->fireOnStats($guzzleOpts, $guzzleRequest, $psrResponse, $e, $response);
$promise->reject(new RequestException($e->getMessage(), $guzzleRequest, $psrResponse, $e));
$response->cancel();
}
}
}
$content = $chunk->getContent();
if ('' !== $content && isset($this->psr7Responses[$response])) {
$this->psr7Responses[$response]->getBody()->write($content);
}
if (!$chunk->isLast()) {
if (true === $breakAfter) {
break;
}
continue;
}
if (!isset($this->pending[$response])) {
unset($this->psr7Responses[$response]);
} else {
$this->resolveResponse($response);
}
if (\in_array($breakAfter, [true, $response], true)) {
break;
}
} catch (TransportExceptionInterface $e) {
if (isset($this->pending[$response])) {
$this->rejectResponse($response, $e);
} else {
unset($this->psr7Responses[$response]);
}
if (\in_array($breakAfter, [true, $response], true)) {
break;
}
} finally {
// Run .then() callbacks; they may add new entries to $this->pending.
$queue->run();
}
}
}
private function resolveResponse(SymfonyResponseInterface $response): void
{
[$guzzleRequest, $options, $promise] = $this->pending[$response];
$psrResponse = $this->psr7Responses[$response];
unset($this->pending[$response], $this->psr7Responses[$response]);
$body = $psrResponse->getBody();
if ($body->isSeekable()) {
try {
$body->seek(0);
} catch (\RuntimeException) {
// ignore
}
}
$this->fireOnStats($options, $guzzleRequest, $psrResponse, null, $response);
$promise->resolve($psrResponse);
}
private function rejectResponse(SymfonyResponseInterface $response, TransportExceptionInterface $e): void
{
[$guzzleRequest, $options, $promise] = $this->pending[$response];
$psrResponse = $this->psr7Responses[$response] ?? null;
unset($this->pending[$response], $this->psr7Responses[$response]);
if ($body = $psrResponse?->getBody()) {
// Headers were already received: use RequestException so Guzzle middleware (e.g. retry)
// can distinguish a mid-stream failure from a connection-level one.
if ($body->isSeekable()) {
try {
$body->seek(0);
} catch (\RuntimeException) {
// ignore
}
}
$this->fireOnStats($options, $guzzleRequest, $psrResponse, $e, $response);
$promise->reject(new RequestException($e->getMessage(), $guzzleRequest, $psrResponse, $e));
} else {
// No headers received: connection-level failure.
$this->fireOnStats($options, $guzzleRequest, null, $e, $response);
$promise->reject(new ConnectException($e->getMessage(), $guzzleRequest, null, [], $e));
}
}
private function fireOnStats(array $options, RequestInterface $request, ?ResponseInterface $psrResponse, ?\Throwable $error, SymfonyResponseInterface $symfonyResponse): void
{
if (!isset($options['on_stats'])) {
return;
}
$handlerStats = $symfonyResponse->getInfo();
($options['on_stats'])(new TransferStats($request, $psrResponse, $handlerStats['total_time'] ?? 0.0, $error, $handlerStats));
}
private function buildSymfonyOptions(RequestInterface $request, array $guzzleOptions): array
{
$options = [];
$options['headers'] = $this->extractHeaders($request, $guzzleOptions);
$this->applyBody($request, $options);
$this->applyAuth($guzzleOptions, $options);
$this->applyTimeouts($guzzleOptions, $options);
$this->applySsl($guzzleOptions, $options);
$this->applyProxy($request, $guzzleOptions, $options);
$this->applyRedirects($guzzleOptions, $options);
$this->applyMisc($request, $guzzleOptions, $options);
$this->applyDecodeContent($guzzleOptions, $options);
if (\extension_loaded('curl') && isset($guzzleOptions['curl'])) {
$this->applyCurlOptions($guzzleOptions['curl'], $options);
}
return $options;
}
/**
* Merges headers from the PSR-7 request with any headers supplied via the
* Guzzle 'headers' option (Guzzle option takes precedence).
*
* @return array<string, string[]>
*/
private function extractHeaders(RequestInterface $request, array $guzzleOptions): array
{
$headers = $request->getHeaders();
foreach ($guzzleOptions['headers'] ?? [] as $name => $value) {
$headers[$name] = (array) $value;
}
return $headers;
}
private function applyBody(RequestInterface $request, array &$options): void
{
$key = 'content-length';
$body = $request->getBody();
if (!$size = $options['headers'][$key][0] ?? $options['headers'][$key = 'Content-Length'][0] ?? $body->getSize() ?? -1) {
return;
}
if ($size < 0 || 1 << 21 < $size) {
$options['body'] = static function (int $size) use ($body) {
if ($body->isSeekable()) {
try {
$body->seek(0);
} catch (\RuntimeException) {
// ignore
}
}
while (!$body->eof()) {
yield $body->read($size);
}
};
} else {
if ($body->isSeekable()) {
try {
$body->seek(0);
} catch (\RuntimeException) {
// ignore
}
}
$options['body'] = $body->getContents();
}
if (0 < $size) {
$options['headers'][$key] = [$size];
}
}
/**
* Maps Guzzle's 'auth' option.
*
* Supported forms:
* ['user', 'pass'] -> auth_basic
* ['user', 'pass', 'basic'] -> auth_basic
* ['token', '', 'bearer'] -> auth_bearer
* ['token', '', 'token'] -> auth_bearer (alias)
*/
private function applyAuth(array $guzzleOptions, array &$options): void
{
if (!isset($guzzleOptions['auth'])) {
return;
}
$auth = $guzzleOptions['auth'];
$type = strtolower($auth[2] ?? 'basic');
if ('bearer' === $type || 'token' === $type) {
$options['auth_bearer'] = $auth[0];
} elseif ('ntlm' === $type) {
array_pop($auth);
$options['auth_ntlm'] = $auth;
} else {
$options['auth_basic'] = [$auth[0], $auth[1] ?? ''];
}
}
private function applyTimeouts(array $guzzleOptions, array &$options): void
{
if (0 < ($guzzleOptions['timeout'] ?? 0)) {
$options['max_duration'] = (float) $guzzleOptions['timeout'];
}
if (0 < ($guzzleOptions['read_timeout'] ?? 0)) {
$options['timeout'] = (float) $guzzleOptions['read_timeout'];
}
if (0 < ($guzzleOptions['connect_timeout'] ?? 0)) {
$options['max_connect_duration'] = (float) $guzzleOptions['connect_timeout'];
}
}
/**
* Maps SSL/TLS related options.
*
* Guzzle 'verify' (bool|string) -> Symfony verify_peer / verify_host / cafile / capath
* Guzzle 'cert' (string|array) -> Symfony local_cert [+ passphrase]
* Guzzle 'ssl_key'(string|array) -> Symfony local_pk [+ passphrase]
* Guzzle 'crypto_method' -> Symfony crypto_method (same PHP stream constants)
*/
private function applySsl(array $guzzleOptions, array &$options): void
{
if (isset($guzzleOptions['verify'])) {
if (false === $guzzleOptions['verify']) {
$options['verify_peer'] = false;
$options['verify_host'] = false;
} elseif (\is_string($guzzleOptions['verify'])) {
if (is_dir($guzzleOptions['verify'])) {
$options['capath'] = $guzzleOptions['verify'];
} else {
$options['cafile'] = $guzzleOptions['verify'];
}
}
}
if (isset($guzzleOptions['cert'])) {
$cert = $guzzleOptions['cert'];
if (\is_array($cert)) {
[$certPath, $certPass] = $cert;
$options['local_cert'] = $certPath;
$options['passphrase'] = $certPass;
} else {
$options['local_cert'] = $cert;
}
}
if (isset($guzzleOptions['ssl_key'])) {
$key = $guzzleOptions['ssl_key'];
if (\is_array($key)) {
[$keyPath, $keyPass] = $key;
$options['local_pk'] = $keyPath;
// Do not clobber a passphrase already set by 'cert'.
$options['passphrase'] ??= $keyPass;
} else {
$options['local_pk'] = $key;
}
}
if (isset($guzzleOptions['crypto_method'])) {
$options['crypto_method'] = $guzzleOptions['crypto_method'];
}
}
/**
* Maps Guzzle's 'proxy' option.
*
* String form -> proxy
* Array form -> selects proxy by URI scheme; 'no' key maps to no_proxy
*/
private function applyProxy(RequestInterface $request, array $guzzleOptions, array &$options): void
{
if (!isset($guzzleOptions['proxy'])) {
return;
}
if (\is_string($proxy = $guzzleOptions['proxy'])) {
$options['proxy'] = $proxy;
return;
}
$scheme = $request->getUri()->getScheme();
if (isset($proxy[$scheme])) {
$options['proxy'] = $proxy[$scheme];
}
if (isset($proxy['no'])) {
$options['no_proxy'] = implode(',', (array) $proxy['no']);
}
}
/**
* Maps Guzzle's 'allow_redirects' to Symfony's 'max_redirects'.
*
* false -> 0 (disable redirects)
* true -> (no override; Symfony defaults apply)
* ['max' => N, ...] -> N
*/
private function applyRedirects(array $guzzleOptions, array &$options): void
{
if (!isset($guzzleOptions['allow_redirects'])) {
return;
}
if (!$ar = $guzzleOptions['allow_redirects']) {
$options['max_redirects'] = 0;
} elseif (\is_array($ar)) {
// 5 matches Guzzle's own default for the 'max' sub-key.
$options['max_redirects'] = $ar['max'] ?? 5;
}
}
/**
* Miscellaneous options that do not fit a dedicated category.
*/
private function applyMisc(RequestInterface $request, array $guzzleOptions, array &$options): void
{
// We always drive I/O via stream(), so tell Symfony not to build its
// own internal buffer - chunks are written directly to the PSR-7 response body stream.
$options['buffer'] = false;
if (!$this->autoUpgradeHttpVersion || '1.0' === $request->getProtocolVersion()) {
$options['http_version'] = $request->getProtocolVersion();
}
// progress callback: (dlTotal, dlNow, ulTotal, ulNow) in Guzzle
// on_progress: (dlNow, dlTotal, info) in Symfony
if (isset($guzzleOptions['progress'])) {
$guzzleProgress = $guzzleOptions['progress'];
$options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use ($guzzleProgress): void {
$guzzleProgress($dlSize, $dlNow, max(0, (int) ($info['upload_content_length'] ?? 0)), (int) ($info['size_upload'] ?? 0));
};
}
}
/**
* Maps Guzzle's 'decode_content' option.
*
* true/string -> remove any explicit Accept-Encoding the caller set, so
* Symfony's HttpClient manages the header and auto-decodes
* false -> ensure an Accept-Encoding header is sent to disable
* Symfony's auto-decode behavior
*/
private function applyDecodeContent(array $guzzleOptions, array &$options): void
{
if ($guzzleOptions['decode_content'] ?? true) {
unset($options['headers']['Accept-Encoding'], $options['headers']['accept-encoding']);
} elseif (!isset($options['headers']['Accept-Encoding']) && !isset($options['headers']['accept-encoding'])) {
$options['headers']['Accept-Encoding'] = ['identity'];
}
}
/**
* Maps raw cURL options from Guzzle's 'curl' option bag to Symfony options.
*
* Constants that have a direct named Symfony equivalent are translated;
* everything else is forwarded verbatim via CurlHttpClient's 'extra.curl'
* pass-through so that no option is silently dropped when the underlying
* transport happens to be CurlHttpClient.
*
* Options managed internally by CurlHttpClient (or Symfony's other
* mechanisms) are silently dropped to avoid the "Cannot set X with
* extra.curl" exception that CurlHttpClient::validateExtraCurlOptions()
* throws for those constants.
*/
private function applyCurlOptions(array $curlOptions, array &$options): void
{
// Build a set of constants that CurlHttpClient rejects in extra.curl
// together with options whose Symfony equivalents are already applied
// via the PSR-7 request or other Guzzle option mappings.
static $blocked;
$blocked ??= array_flip(array_filter([
// Auth - handled by applyAuth() / requires NTLM-specific logic.
\CURLOPT_HTTPAUTH, \CURLOPT_USERPWD,
// Body - set from the PSR-7 request body by applyBody().
\CURLOPT_READDATA, \CURLOPT_READFUNCTION, \CURLOPT_INFILESIZE,
\CURLOPT_POSTFIELDS, \CURLOPT_UPLOAD,
// HTTP method - taken from the PSR-7 request.
\CURLOPT_POST, \CURLOPT_PUT, \CURLOPT_CUSTOMREQUEST,
\CURLOPT_HTTPGET, \CURLOPT_NOBODY,
// Headers - merged by extractHeaders().
\CURLOPT_HTTPHEADER,
// Internal curl signal / redirect-type flags with no Symfony equiv.
\CURLOPT_NOSIGNAL, \CURLOPT_POSTREDIR,
// Progress - handled by applyMisc() via Guzzle's 'progress' option.
\CURLOPT_NOPROGRESS, \CURLOPT_PROGRESSFUNCTION,
// Blocked by CurlHttpClient::validateExtraCurlOptions().
\CURLOPT_PRIVATE, \CURLOPT_HEADERFUNCTION, \CURLOPT_WRITEFUNCTION,
\CURLOPT_VERBOSE, \CURLOPT_STDERR, \CURLOPT_RETURNTRANSFER,
\CURLOPT_URL, \CURLOPT_FOLLOWLOCATION, \CURLOPT_HEADER,
\CURLOPT_HTTP_VERSION, \CURLOPT_PORT, \CURLOPT_DNS_USE_GLOBAL_CACHE,
\CURLOPT_PROTOCOLS, \CURLOPT_REDIR_PROTOCOLS, \CURLOPT_COOKIEFILE,
\CURLINFO_REDIRECT_COUNT,
\defined('CURLOPT_HTTP09_ALLOWED') ? \CURLOPT_HTTP09_ALLOWED : null,
\defined('CURLOPT_HEADEROPT') ? \CURLOPT_HEADEROPT : null,
// Pinned public key: curl uses "sha256//base64" which is
// incompatible with Symfony's peer_fingerprint array format.
\defined('CURLOPT_PINNEDPUBLICKEY') ? \CURLOPT_PINNEDPUBLICKEY : null,
]));
foreach ($curlOptions as $opt => $value) {
if (isset($blocked[$opt])) {
continue;
}
// CURLOPT_UNIX_SOCKET_PATH is conditionally defined; maps to bindto.
if (\defined('CURLOPT_UNIX_SOCKET_PATH') && \CURLOPT_UNIX_SOCKET_PATH === $opt) {
$options['bindto'] = $value;
continue;
}
match ($opt) {
\CURLOPT_CAINFO => $options['cafile'] = $value,
\CURLOPT_CAPATH => $options['capath'] = $value,
\CURLOPT_SSLCERT => $options['local_cert'] = $value,
\CURLOPT_SSLKEY => $options['local_pk'] = $value,
\CURLOPT_SSLCERTPASSWD,
\CURLOPT_SSLKEYPASSWD => $options['passphrase'] = $value,
\CURLOPT_SSL_CIPHER_LIST => $options['ciphers'] = $value,
\CURLOPT_CERTINFO => $options['capture_peer_cert_chain'] = (bool) $value,
\CURLOPT_PROXY => $options['proxy'] = $value,
\CURLOPT_NOPROXY => $options['no_proxy'] = $value,
\CURLOPT_USERAGENT => $options['headers']['User-Agent'] = [$value],
\CURLOPT_REFERER => $options['headers']['Referer'] = [$value],
\CURLOPT_INTERFACE => $options['bindto'] = $value,
\CURLOPT_SSL_VERIFYPEER => $options['verify_peer'] = (bool) $value,
\CURLOPT_SSL_VERIFYHOST => $options['verify_host'] = $value > 0,
\CURLOPT_MAXREDIRS => $options['max_redirects'] = $value,
\CURLOPT_TIMEOUT => $options['max_duration'] = (float) $value,
\CURLOPT_TIMEOUT_MS => $options['max_duration'] = $value / 1000.0,
\CURLOPT_CONNECTTIMEOUT => $options['max_connect_duration'] = (float) $value,
\CURLOPT_CONNECTTIMEOUT_MS => $options['max_connect_duration'] = $value / 1000.0,
default => $options['extra']['curl'][$opt] = $value,
};
}
}
}