← All changes
|
includes/sdk/google/guzzlehttp/guzzle/src/Handler/CurlFactory.php
+54
-50
1.2.13
→
1.4.2
View file →
| @@ -1,18 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace Dudlewebs\WPMCS\GuzzleHttp\Handler; | |
| 3 | +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp\Handler; | |
| 4 | 4 | |
| 5 | -use Dudlewebs\WPMCS\GuzzleHttp\Exception\ConnectException; | |
| 6 | -use Dudlewebs\WPMCS\GuzzleHttp\Exception\RequestException; | |
| 7 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise as P; | |
| 8 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise\FulfilledPromise; | |
| 9 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise\PromiseInterface; | |
| 10 | -use Dudlewebs\WPMCS\GuzzleHttp\Psr7\LazyOpenStream; | |
| 11 | -use Dudlewebs\WPMCS\GuzzleHttp\TransferStats; | |
| 12 | -use Dudlewebs\WPMCS\GuzzleHttp\Utils; | |
| 13 | -use Dudlewebs\WPMCS\Psr\Http\Message\RequestInterface; | |
| 14 | -use Dudlewebs\WPMCS\Psr\Http\Message\UriInterface; | |
| 5 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Exception\ConnectException; | |
| 6 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Exception\RequestException; | |
| 7 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise as P; | |
| 8 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\FulfilledPromise; | |
| 9 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\PromiseInterface; | |
| 10 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\LazyOpenStream; | |
| 11 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\TransferStats; | |
| 12 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Utils; | |
| 13 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\RequestInterface; | |
| 14 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\UriInterface; | |
| 15 | 15 | /** |
| 16 | 16 | * Creates curl resources from a request |
| 17 | 17 | * |
| 18 | 18 | * @final |
| @@ -38,9 +38,9 @@ | ||
| 38 | 38 | public function __construct(int $maxHandles) |
| 39 | 39 | { |
| 40 | 40 | $this->maxHandles = $maxHandles; |
| 41 | 41 | } |
| 42 | - public function create(RequestInterface $request, array $options): EasyHandle | |
| 42 | + public function create(RequestInterface $request, array $options) : EasyHandle | |
| 43 | 43 | { |
| 44 | 44 | $protocolVersion = $request->getProtocolVersion(); |
| 45 | 45 | if ('2' === $protocolVersion || '2.0' === $protocolVersion) { |
| 46 | 46 | if (!self::supportsHttp2()) { |
| @@ -46,9 +46,9 @@ | ||
| 46 | 46 | if (!self::supportsHttp2()) { |
| 47 | 47 | throw new ConnectException('HTTP/2 is supported by the cURL handler, however libcurl is built without HTTP/2 support.', $request); |
| 48 | 48 | } |
| 49 | 49 | } elseif ('1.0' !== $protocolVersion && '1.1' !== $protocolVersion) { |
| 50 | - throw new ConnectException(sprintf('HTTP/%s is not supported by the cURL handler.', $protocolVersion), $request); | |
| 50 | + throw new ConnectException(\sprintf('HTTP/%s is not supported by the cURL handler.', $protocolVersion), $request); | |
| 51 | 51 | } |
| 52 | 52 | if (isset($options['curl']['body_as_string'])) { |
| 53 | 53 | $options['_body_as_string'] = $options['curl']['body_as_string']; |
| 54 | 54 | unset($options['curl']['body_as_string']); |
| @@ -66,20 +66,20 @@ | ||
| 66 | 66 | $conf = \array_replace($conf, $options['curl']); |
| 67 | 67 | } |
| 68 | 68 | $conf[\CURLOPT_HEADERFUNCTION] = $this->createHeaderFn($easy); |
| 69 | 69 | $easy->handle = $this->handles ? \array_pop($this->handles) : \curl_init(); |
| 70 | - curl_setopt_array($easy->handle, $conf); | |
| 70 | + \curl_setopt_array($easy->handle, $conf); | |
| 71 | 71 | return $easy; |
| 72 | 72 | } |
| 73 | - private static function supportsHttp2(): bool | |
| 73 | + private static function supportsHttp2() : bool | |
| 74 | 74 | { |
| 75 | 75 | static $supportsHttp2 = null; |
| 76 | 76 | if (null === $supportsHttp2) { |
| 77 | - $supportsHttp2 = self::supportsTls12() && defined('CURL_VERSION_HTTP2') && \CURL_VERSION_HTTP2 & \curl_version()['features']; | |
| 77 | + $supportsHttp2 = self::supportsTls12() && \defined('CURL_VERSION_HTTP2') && \CURL_VERSION_HTTP2 & \curl_version()['features']; | |
| 78 | 78 | } |
| 79 | 79 | return $supportsHttp2; |
| 80 | 80 | } |
| 81 | - private static function supportsTls12(): bool | |
| 81 | + private static function supportsTls12() : bool | |
| 82 | 82 | { |
| 83 | 83 | static $supportsTls12 = null; |
| 84 | 84 | if (null === $supportsTls12) { |
| 85 | 85 | $supportsTls12 = \CURL_SSLVERSION_TLSv1_2 & \curl_version()['features']; |
| @@ -85,22 +85,24 @@ | ||
| 85 | 85 | $supportsTls12 = \CURL_SSLVERSION_TLSv1_2 & \curl_version()['features']; |
| 86 | 86 | } |
| 87 | 87 | return $supportsTls12; |
| 88 | 88 | } |
| 89 | - private static function supportsTls13(): bool | |
| 89 | + private static function supportsTls13() : bool | |
| 90 | 90 | { |
| 91 | 91 | static $supportsTls13 = null; |
| 92 | 92 | if (null === $supportsTls13) { |
| 93 | - $supportsTls13 = defined('CURL_SSLVERSION_TLSv1_3') && \CURL_SSLVERSION_TLSv1_3 & \curl_version()['features']; | |
| 93 | + $supportsTls13 = \defined('CURL_SSLVERSION_TLSv1_3') && \CURL_SSLVERSION_TLSv1_3 & \curl_version()['features']; | |
| 94 | 94 | } |
| 95 | 95 | return $supportsTls13; |
| 96 | 96 | } |
| 97 | - public function release(EasyHandle $easy): void | |
| 97 | + public function release(EasyHandle $easy) : void | |
| 98 | 98 | { |
| 99 | 99 | $resource = $easy->handle; |
| 100 | 100 | unset($easy->handle); |
| 101 | 101 | if (\count($this->handles) >= $this->maxHandles) { |
| 102 | - \curl_close($resource); | |
| 102 | + if (\PHP_VERSION_ID < 80000) { | |
| 103 | + \curl_close($resource); | |
| 104 | + } | |
| 103 | 105 | } else { |
| 104 | 106 | // Remove all callback functions as they can hold onto references |
| 105 | 107 | // and are not cleaned up by curl_reset. Using curl_setopt_array |
| 106 | 108 | // does not work for some reason, so removing each one |
| @@ -119,9 +121,9 @@ | ||
| 119 | 121 | * |
| 120 | 122 | * @param callable(RequestInterface, array): PromiseInterface $handler |
| 121 | 123 | * @param CurlFactoryInterface $factory Dictates how the handle is released |
| 122 | 124 | */ |
| 123 | - public static function finish(callable $handler, EasyHandle $easy, CurlFactoryInterface $factory): PromiseInterface | |
| 125 | + public static function finish(callable $handler, EasyHandle $easy, CurlFactoryInterface $factory) : PromiseInterface | |
| 124 | 126 | { |
| 125 | 127 | if (isset($easy->options['on_stats'])) { |
| 126 | 128 | self::invokeStats($easy); |
| 127 | 129 | } |
| @@ -136,9 +138,9 @@ | ||
| 136 | 138 | $body->rewind(); |
| 137 | 139 | } |
| 138 | 140 | return new FulfilledPromise($easy->response); |
| 139 | 141 | } |
| 140 | - private static function invokeStats(EasyHandle $easy): void | |
| 142 | + private static function invokeStats(EasyHandle $easy) : void | |
| 141 | 143 | { |
| 142 | 144 | $curlStats = \curl_getinfo($easy->handle); |
| 143 | 145 | $curlStats['appconnect_time'] = \curl_getinfo($easy->handle, \CURLINFO_APPCONNECT_TIME); |
| 144 | 146 | $stats = new TransferStats($easy->request, $easy->response, $curlStats['total_time'], $easy->errno, $curlStats); |
| @@ -146,9 +148,9 @@ | ||
| 146 | 148 | } |
| 147 | 149 | /** |
| 148 | 150 | * @param callable(RequestInterface, array): PromiseInterface $handler |
| 149 | 151 | */ |
| 150 | - private static function finishError(callable $handler, EasyHandle $easy, CurlFactoryInterface $factory): PromiseInterface | |
| 152 | + private static function finishError(callable $handler, EasyHandle $easy, CurlFactoryInterface $factory) : PromiseInterface | |
| 151 | 153 | { |
| 152 | 154 | // Get error information and release the handle to the factory. |
| 153 | 155 | $ctx = ['errno' => $easy->errno, 'error' => \curl_error($easy->handle), 'appconnect_time' => \curl_getinfo($easy->handle, \CURLINFO_APPCONNECT_TIME)] + \curl_getinfo($easy->handle); |
| 154 | 156 | $ctx[self::CURL_VERSION_STR] = self::getCurlVersion(); |
| @@ -158,9 +160,9 @@ | ||
| 158 | 160 | return self::retryFailedRewind($handler, $easy, $ctx); |
| 159 | 161 | } |
| 160 | 162 | return self::createRejection($easy, $ctx); |
| 161 | 163 | } |
| 162 | - private static function getCurlVersion(): string | |
| 164 | + private static function getCurlVersion() : string | |
| 163 | 165 | { |
| 164 | 166 | static $curlVersion = null; |
| 165 | 167 | if (null === $curlVersion) { |
| 166 | 168 | $curlVersion = \curl_version()['version']; |
| @@ -166,9 +168,9 @@ | ||
| 166 | 168 | $curlVersion = \curl_version()['version']; |
| 167 | 169 | } |
| 168 | 170 | return $curlVersion; |
| 169 | 171 | } |
| 170 | - private static function createRejection(EasyHandle $easy, array $ctx): PromiseInterface | |
| 172 | + private static function createRejection(EasyHandle $easy, array $ctx) : PromiseInterface | |
| 171 | 173 | { |
| 172 | 174 | static $connectionErrors = [\CURLE_OPERATION_TIMEOUTED => \true, \CURLE_COULDNT_RESOLVE_HOST => \true, \CURLE_COULDNT_CONNECT => \true, \CURLE_SSL_CONNECT_ERROR => \true, \CURLE_GOT_NOTHING => \true]; |
| 173 | 175 | if ($easy->createResponseException) { |
| 174 | 176 | return P\Create::rejectionFor(new RequestException('An error was encountered while creating the response', $easy->request, $easy->response, $easy->createResponseException, $ctx)); |
| @@ -181,9 +183,9 @@ | ||
| 181 | 183 | $uri = $easy->request->getUri(); |
| 182 | 184 | $sanitizedError = self::sanitizeCurlError($ctx['error'] ?? '', $uri); |
| 183 | 185 | $message = \sprintf('cURL error %s: %s (%s)', $ctx['errno'], $sanitizedError, 'see https://curl.haxx.se/libcurl/c/libcurl-errors.html'); |
| 184 | 186 | if ('' !== $sanitizedError) { |
| 185 | - $redactedUriString = \Dudlewebs\WPMCS\GuzzleHttp\Psr7\Utils::redactUserInfo($uri)->__toString(); | |
| 187 | + $redactedUriString = \Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Utils::redactUserInfo($uri)->__toString(); | |
| 186 | 188 | if ($redactedUriString !== '' && \false === \strpos($sanitizedError, $redactedUriString)) { |
| 187 | 189 | $message .= \sprintf(' for %s', $redactedUriString); |
| 188 | 190 | } |
| 189 | 191 | } |
| @@ -190,9 +192,9 @@ | ||
| 190 | 192 | // Create a connection exception if it was a specific error code. |
| 191 | 193 | $error = isset($connectionErrors[$easy->errno]) ? new ConnectException($message, $easy->request, null, $ctx) : new RequestException($message, $easy->request, $easy->response, null, $ctx); |
| 192 | 194 | return P\Create::rejectionFor($error); |
| 193 | 195 | } |
| 194 | - private static function sanitizeCurlError(string $error, UriInterface $uri): string | |
| 196 | + private static function sanitizeCurlError(string $error, UriInterface $uri) : string | |
| 195 | 197 | { |
| 196 | 198 | if ('' === $error) { |
| 197 | 199 | return $error; |
| 198 | 200 | } |
| @@ -200,15 +202,15 @@ | ||
| 200 | 202 | $baseUriString = $baseUri->__toString(); |
| 201 | 203 | if ('' === $baseUriString) { |
| 202 | 204 | return $error; |
| 203 | 205 | } |
| 204 | - $redactedUriString = \Dudlewebs\WPMCS\GuzzleHttp\Psr7\Utils::redactUserInfo($baseUri)->__toString(); | |
| 205 | - return str_replace($baseUriString, $redactedUriString, $error); | |
| 206 | + $redactedUriString = \Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Utils::redactUserInfo($baseUri)->__toString(); | |
| 207 | + return \str_replace($baseUriString, $redactedUriString, $error); | |
| 206 | 208 | } |
| 207 | 209 | /** |
| 208 | 210 | * @return array<int|string, mixed> |
| 209 | 211 | */ |
| 210 | - private function getDefaultConf(EasyHandle $easy): array | |
| 212 | + private function getDefaultConf(EasyHandle $easy) : array | |
| 211 | 213 | { |
| 212 | 214 | $conf = ['_headers' => $easy->request->getHeaders(), \CURLOPT_CUSTOMREQUEST => $easy->request->getMethod(), \CURLOPT_URL => (string) $easy->request->getUri()->withFragment(''), \CURLOPT_RETURNTRANSFER => \false, \CURLOPT_HEADER => \false, \CURLOPT_CONNECTTIMEOUT => 300]; |
| 213 | 215 | if (\defined('CURLOPT_PROTOCOLS')) { |
| 214 | 216 | $conf[\CURLOPT_PROTOCOLS] = \CURLPROTO_HTTP | \CURLPROTO_HTTPS; |
| @@ -222,9 +224,9 @@ | ||
| 222 | 224 | $conf[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_1_0; |
| 223 | 225 | } |
| 224 | 226 | return $conf; |
| 225 | 227 | } |
| 226 | - private function applyMethod(EasyHandle $easy, array &$conf): void | |
| 228 | + private function applyMethod(EasyHandle $easy, array &$conf) : void | |
| 227 | 229 | { |
| 228 | 230 | $body = $easy->request->getBody(); |
| 229 | 231 | $size = $body->getSize(); |
| 230 | 232 | if ($size === null || $size > 0) { |
| @@ -241,9 +243,9 @@ | ||
| 241 | 243 | $conf[\CURLOPT_NOBODY] = \true; |
| 242 | 244 | unset($conf[\CURLOPT_WRITEFUNCTION], $conf[\CURLOPT_READFUNCTION], $conf[\CURLOPT_FILE], $conf[\CURLOPT_INFILE]); |
| 243 | 245 | } |
| 244 | 246 | } |
| 245 | - private function applyBody(RequestInterface $request, array $options, array &$conf): void | |
| 247 | + private function applyBody(RequestInterface $request, array $options, array &$conf) : void | |
| 246 | 248 | { |
| 247 | 249 | $size = $request->hasHeader('Content-Length') ? (int) $request->getHeaderLine('Content-Length') : null; |
| 248 | 250 | // Send the body as a string if the size is less than 1MB OR if the |
| 249 | 251 | // [curl][body_as_string] request value is set. |
| @@ -261,9 +263,9 @@ | ||
| 261 | 263 | $body = $request->getBody(); |
| 262 | 264 | if ($body->isSeekable()) { |
| 263 | 265 | $body->rewind(); |
| 264 | 266 | } |
| 265 | - $conf[\CURLOPT_READFUNCTION] = static function ($ch, $fd, $length) use ($body) { | |
| 267 | + $conf[\CURLOPT_READFUNCTION] = static function ($ch, $fd, $length) use($body) { | |
| 266 | 268 | return $body->read($length); |
| 267 | 269 | }; |
| 268 | 270 | } |
| 269 | 271 | // If the Expect header is not present, prevent curl from adding it |
| @@ -274,9 +276,9 @@ | ||
| 274 | 276 | if (!$request->hasHeader('Content-Type')) { |
| 275 | 277 | $conf[\CURLOPT_HTTPHEADER][] = 'Content-Type:'; |
| 276 | 278 | } |
| 277 | 279 | } |
| 278 | - private function applyHeaders(EasyHandle $easy, array &$conf): void | |
| 280 | + private function applyHeaders(EasyHandle $easy, array &$conf) : void | |
| 279 | 281 | { |
| 280 | 282 | foreach ($conf['_headers'] as $name => $values) { |
| 281 | 283 | foreach ($values as $value) { |
| 282 | 284 | $value = (string) $value; |
| @@ -299,9 +301,9 @@ | ||
| 299 | 301 | * |
| 300 | 302 | * @param string $name Case-insensitive header to remove |
| 301 | 303 | * @param array $options Array of options to modify |
| 302 | 304 | */ |
| 303 | - private function removeHeader(string $name, array &$options): void | |
| 305 | + private function removeHeader(string $name, array &$options) : void | |
| 304 | 306 | { |
| 305 | 307 | foreach (\array_keys($options['_headers']) as $key) { |
| 306 | 308 | if (!\strcasecmp($key, $name)) { |
| 307 | 309 | unset($options['_headers'][$key]); |
| @@ -308,9 +310,9 @@ | ||
| 308 | 310 | return; |
| 309 | 311 | } |
| 310 | 312 | } |
| 311 | 313 | } |
| 312 | - private function applyHandlerOptions(EasyHandle $easy, array &$conf): void | |
| 314 | + private function applyHandlerOptions(EasyHandle $easy, array &$conf) : void | |
| 313 | 315 | { |
| 314 | 316 | $options = $easy->options; |
| 315 | 317 | if (isset($options['verify'])) { |
| 316 | 318 | if ($options['verify'] === \false) { |
| @@ -351,13 +353,13 @@ | ||
| 351 | 353 | } |
| 352 | 354 | } |
| 353 | 355 | if (!isset($options['sink'])) { |
| 354 | 356 | // Use a default temp stream if no sink was set. |
| 355 | - $options['sink'] = \Dudlewebs\WPMCS\GuzzleHttp\Psr7\Utils::tryFopen('php://temp', 'w+'); | |
| 357 | + $options['sink'] = \Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Utils::tryFopen('php://temp', 'w+'); | |
| 356 | 358 | } |
| 357 | 359 | $sink = $options['sink']; |
| 358 | 360 | if (!\is_string($sink)) { |
| 359 | - $sink = \Dudlewebs\WPMCS\GuzzleHttp\Psr7\Utils::streamFor($sink); | |
| 361 | + $sink = \Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Utils::streamFor($sink); | |
| 360 | 362 | } elseif (!\is_dir(\dirname($sink))) { |
| 361 | 363 | // Ensure that the directory exists before failing in curl. |
| 362 | 364 | throw new \RuntimeException(\sprintf('Directory %s does not exist for sink value of %s', \dirname($sink), $sink)); |
| 363 | 365 | } else { |
| @@ -363,9 +365,9 @@ | ||
| 363 | 365 | } else { |
| 364 | 366 | $sink = new LazyOpenStream($sink, 'w+'); |
| 365 | 367 | } |
| 366 | 368 | $easy->sink = $sink; |
| 367 | - $conf[\CURLOPT_WRITEFUNCTION] = static function ($ch, $write) use ($sink): int { | |
| 369 | + $conf[\CURLOPT_WRITEFUNCTION] = static function ($ch, $write) use($sink) : int { | |
| 368 | 370 | return $sink->write($write); |
| 369 | 371 | }; |
| 370 | 372 | $timeoutRequiresNoSignal = \false; |
| 371 | 373 | if (isset($options['timeout'])) { |
| @@ -407,9 +409,9 @@ | ||
| 407 | 409 | // If HTTP/2, upgrade TLS 1.0 and 1.1 to 1.2 |
| 408 | 410 | if ('2' === $protocolVersion || '2.0' === $protocolVersion) { |
| 409 | 411 | if (\STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT === $options['crypto_method'] || \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT === $options['crypto_method'] || \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT === $options['crypto_method']) { |
| 410 | 412 | $conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_2; |
| 411 | - } elseif (defined('STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT') && \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT === $options['crypto_method']) { | |
| 413 | + } elseif (\defined('STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT') && \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT === $options['crypto_method']) { | |
| 412 | 414 | if (!self::supportsTls13()) { |
| 413 | 415 | throw new \InvalidArgumentException('Invalid crypto_method request option: TLS 1.3 not supported by your version of cURL'); |
| 414 | 416 | } |
| 415 | 417 | $conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_3; |
| @@ -424,9 +426,9 @@ | ||
| 424 | 426 | if (!self::supportsTls12()) { |
| 425 | 427 | throw new \InvalidArgumentException('Invalid crypto_method request option: TLS 1.2 not supported by your version of cURL'); |
| 426 | 428 | } |
| 427 | 429 | $conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_2; |
| 428 | - } elseif (defined('STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT') && \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT === $options['crypto_method']) { | |
| 430 | + } elseif (\defined('STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT') && \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT === $options['crypto_method']) { | |
| 429 | 431 | if (!self::supportsTls13()) { |
| 430 | 432 | throw new \InvalidArgumentException('Invalid crypto_method request option: TLS 1.3 not supported by your version of cURL'); |
| 431 | 433 | } |
| 432 | 434 | $conf[\CURLOPT_SSLVERSION] = \CURL_SSLVERSION_TLSv1_3; |
| @@ -444,11 +446,11 @@ | ||
| 444 | 446 | throw new \InvalidArgumentException("SSL certificate not found: {$cert}"); |
| 445 | 447 | } |
| 446 | 448 | // OpenSSL (versions 0.9.3 and later) also support "P12" for PKCS#12-encoded files. |
| 447 | 449 | // see https://curl.se/libcurl/c/CURLOPT_SSLCERTTYPE.html |
| 448 | - $ext = pathinfo($cert, \PATHINFO_EXTENSION); | |
| 449 | - if (preg_match('#^(der|p12)$#i', $ext)) { | |
| 450 | - $conf[\CURLOPT_SSLCERTTYPE] = strtoupper($ext); | |
| 450 | + $ext = \pathinfo($cert, \PATHINFO_EXTENSION); | |
| 451 | + if (\preg_match('#^(der|p12)$#i', $ext)) { | |
| 452 | + $conf[\CURLOPT_SSLCERTTYPE] = \strtoupper($ext); | |
| 451 | 453 | } |
| 452 | 454 | $conf[\CURLOPT_SSLCERT] = $cert; |
| 453 | 455 | } |
| 454 | 456 | if (isset($options['ssl_key'])) { |
| @@ -470,9 +472,9 @@ | ||
| 470 | 472 | if (!\is_callable($progress)) { |
| 471 | 473 | throw new \InvalidArgumentException('progress client option must be callable'); |
| 472 | 474 | } |
| 473 | 475 | $conf[\CURLOPT_NOPROGRESS] = \false; |
| 474 | - $conf[\CURLOPT_PROGRESSFUNCTION] = static function ($resource, int $downloadSize, int $downloaded, int $uploadSize, int $uploaded) use ($progress) { | |
| 476 | + $conf[\CURLOPT_PROGRESSFUNCTION] = static function ($resource, int $downloadSize, int $downloaded, int $uploadSize, int $uploaded) use($progress) { | |
| 475 | 477 | $progress($downloadSize, $downloaded, $uploadSize, $uploaded); |
| 476 | 478 | }; |
| 477 | 479 | } |
| 478 | 480 | if (!empty($options['debug'])) { |
| @@ -490,9 +492,9 @@ | ||
| 490 | 492 | * without an error status. |
| 491 | 493 | * |
| 492 | 494 | * @param callable(RequestInterface, array): PromiseInterface $handler |
| 493 | 495 | */ |
| 494 | - private static function retryFailedRewind(callable $handler, EasyHandle $easy, array $ctx): PromiseInterface | |
| 496 | + private static function retryFailedRewind(callable $handler, EasyHandle $easy, array $ctx) : PromiseInterface | |
| 495 | 497 | { |
| 496 | 498 | try { |
| 497 | 499 | // Only rewind if the body has been read from. |
| 498 | 500 | $body = $easy->request->getBody(); |
| @@ -513,9 +515,9 @@ | ||
| 513 | 515 | ++$easy->options['_curl_retries']; |
| 514 | 516 | } |
| 515 | 517 | return $handler($easy->request, $easy->options); |
| 516 | 518 | } |
| 517 | - private function createHeaderFn(EasyHandle $easy): callable | |
| 519 | + private function createHeaderFn(EasyHandle $easy) : callable | |
| 518 | 520 | { |
| 519 | 521 | if (isset($easy->options['on_headers'])) { |
| 520 | 522 | $onHeaders = $easy->options['on_headers']; |
| 521 | 523 | if (!\is_callable($onHeaders)) { |
| @@ -523,9 +525,9 @@ | ||
| 523 | 525 | } |
| 524 | 526 | } else { |
| 525 | 527 | $onHeaders = null; |
| 526 | 528 | } |
| 527 | - return static function ($ch, $h) use ($onHeaders, $easy, &$startingResponse) { | |
| 529 | + return static function ($ch, $h) use($onHeaders, $easy, &$startingResponse) { | |
| 528 | 530 | $value = \trim($h); |
| 529 | 531 | if ($value === '') { |
| 530 | 532 | $startingResponse = \true; |
| 531 | 533 | try { |
| @@ -555,9 +557,11 @@ | ||
| 555 | 557 | } |
| 556 | 558 | public function __destruct() |
| 557 | 559 | { |
| 558 | 560 | foreach ($this->handles as $id => $handle) { |
| 559 | - \curl_close($handle); | |
| 561 | + if (\PHP_VERSION_ID < 80000) { | |
| 562 | + \curl_close($handle); | |
| 563 | + } | |
| 560 | 564 | unset($this->handles[$id]); |
| 561 | 565 | } |
| 562 | 566 | } |
| 563 | 567 | } |