vendor/symfony/http-client/CurlHttpClient.php line 317

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpClient;
  11. use Psr\Log\LoggerAwareInterface;
  12. use Psr\Log\LoggerInterface;
  13. use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
  14. use Symfony\Component\HttpClient\Exception\TransportException;
  15. use Symfony\Component\HttpClient\Internal\CurlClientState;
  16. use Symfony\Component\HttpClient\Internal\PushedResponse;
  17. use Symfony\Component\HttpClient\Response\CurlResponse;
  18. use Symfony\Component\HttpClient\Response\ResponseStream;
  19. use Symfony\Contracts\HttpClient\HttpClientInterface;
  20. use Symfony\Contracts\HttpClient\ResponseInterface;
  21. use Symfony\Contracts\HttpClient\ResponseStreamInterface;
  22. use Symfony\Contracts\Service\ResetInterface;
  23. /**
  24.  * A performant implementation of the HttpClientInterface contracts based on the curl extension.
  25.  *
  26.  * This provides fully concurrent HTTP requests, with transparent
  27.  * HTTP/2 push when a curl version that supports it is installed.
  28.  *
  29.  * @author Nicolas Grekas <p@tchwork.com>
  30.  */
  31. final class CurlHttpClient implements HttpClientInterfaceLoggerAwareInterfaceResetInterface
  32. {
  33.     use HttpClientTrait;
  34.     private array $defaultOptions self::OPTIONS_DEFAULTS + [
  35.         'auth_ntlm' => null// array|string - an array containing the username as first value, and optionally the
  36.                              //   password as the second one; or string like username:password - enabling NTLM auth
  37.         'extra' => [
  38.             'curl' => [],    // A list of extra curl options indexed by their corresponding CURLOPT_*
  39.         ],
  40.     ];
  41.     private static array $emptyDefaults self::OPTIONS_DEFAULTS + ['auth_ntlm' => null];
  42.     private ?LoggerInterface $logger null;
  43.     /**
  44.      * An internal object to share state between the client and its responses.
  45.      */
  46.     private CurlClientState $multi;
  47.     /**
  48.      * @param array $defaultOptions     Default request's options
  49.      * @param int   $maxHostConnections The maximum number of connections to a single host
  50.      * @param int   $maxPendingPushes   The maximum number of pushed responses to accept in the queue
  51.      *
  52.      * @see HttpClientInterface::OPTIONS_DEFAULTS for available options
  53.      */
  54.     public function __construct(array $defaultOptions = [], int $maxHostConnections 6int $maxPendingPushes 50)
  55.     {
  56.         if (!\extension_loaded('curl')) {
  57.             throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\CurlHttpClient" as the "curl" extension is not installed.');
  58.         }
  59.         $this->defaultOptions['buffer'] ??= self::shouldBuffer(...);
  60.         if ($defaultOptions) {
  61.             [, $this->defaultOptions] = self::prepareRequest(nullnull$defaultOptions$this->defaultOptions);
  62.         }
  63.         $this->multi = new CurlClientState($maxHostConnections$maxPendingPushes);
  64.     }
  65.     public function setLogger(LoggerInterface $logger): void
  66.     {
  67.         $this->logger $this->multi->logger $logger;
  68.     }
  69.     /**
  70.      * @see HttpClientInterface::OPTIONS_DEFAULTS for available options
  71.      *
  72.      * {@inheritdoc}
  73.      */
  74.     public function request(string $methodstring $url, array $options = []): ResponseInterface
  75.     {
  76.         [$url$options] = self::prepareRequest($method$url$options$this->defaultOptions);
  77.         $scheme $url['scheme'];
  78.         $authority $url['authority'];
  79.         $host parse_url($authority\PHP_URL_HOST);
  80.         $port parse_url($authority\PHP_URL_PORT) ?: ('http:' === $scheme 80 443);
  81.         $proxy $options['proxy']
  82.             ?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null null)
  83.             // Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
  84.             ?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli''phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null;
  85.         $url implode(''$url);
  86.         if (!isset($options['normalized_headers']['user-agent'])) {
  87.             $options['headers'][] = 'User-Agent: Symfony HttpClient/Curl';
  88.         }
  89.         $curlopts = [
  90.             \CURLOPT_URL => $url,
  91.             \CURLOPT_TCP_NODELAY => true,
  92.             \CURLOPT_PROTOCOLS => \CURLPROTO_HTTP \CURLPROTO_HTTPS,
  93.             \CURLOPT_REDIR_PROTOCOLS => \CURLPROTO_HTTP \CURLPROTO_HTTPS,
  94.             \CURLOPT_FOLLOWLOCATION => true,
  95.             \CURLOPT_MAXREDIRS => $options['max_redirects'] ? $options['max_redirects'] : 0,
  96.             \CURLOPT_COOKIEFILE => ''// Keep track of cookies during redirects
  97.             \CURLOPT_TIMEOUT => 0,
  98.             \CURLOPT_PROXY => $proxy,
  99.             \CURLOPT_NOPROXY => $options['no_proxy'] ?? $_SERVER['no_proxy'] ?? $_SERVER['NO_PROXY'] ?? '',
  100.             \CURLOPT_SSL_VERIFYPEER => $options['verify_peer'],
  101.             \CURLOPT_SSL_VERIFYHOST => $options['verify_host'] ? 0,
  102.             \CURLOPT_CAINFO => $options['cafile'],
  103.             \CURLOPT_CAPATH => $options['capath'],
  104.             \CURLOPT_SSL_CIPHER_LIST => $options['ciphers'],
  105.             \CURLOPT_SSLCERT => $options['local_cert'],
  106.             \CURLOPT_SSLKEY => $options['local_pk'],
  107.             \CURLOPT_KEYPASSWD => $options['passphrase'],
  108.             \CURLOPT_CERTINFO => $options['capture_peer_cert_chain'],
  109.         ];
  110.         if (1.0 === (float) $options['http_version']) {
  111.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_1_0;
  112.         } elseif (1.1 === (float) $options['http_version']) {
  113.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_1_1;
  114.         } elseif (\defined('CURL_VERSION_HTTP2') && (\CURL_VERSION_HTTP2 CurlClientState::$curlVersion['features']) && ('https:' === $scheme || 2.0 === (float) $options['http_version'])) {
  115.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_2_0;
  116.         }
  117.         if (isset($options['auth_ntlm'])) {
  118.             $curlopts[\CURLOPT_HTTPAUTH] = \CURLAUTH_NTLM;
  119.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_1_1;
  120.             if (\is_array($options['auth_ntlm'])) {
  121.                 $count \count($options['auth_ntlm']);
  122.                 if ($count <= || $count 2) {
  123.                     throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must contain 1 or 2 elements, %d given.'$count));
  124.                 }
  125.                 $options['auth_ntlm'] = implode(':'$options['auth_ntlm']);
  126.             }
  127.             if (!\is_string($options['auth_ntlm'])) {
  128.                 throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must be a string or an array, "%s" given.'get_debug_type($options['auth_ntlm'])));
  129.             }
  130.             $curlopts[\CURLOPT_USERPWD] = $options['auth_ntlm'];
  131.         }
  132.         if (!\ZEND_THREAD_SAFE) {
  133.             $curlopts[\CURLOPT_DNS_USE_GLOBAL_CACHE] = false;
  134.         }
  135.         if (\defined('CURLOPT_HEADEROPT') && \defined('CURLHEADER_SEPARATE')) {
  136.             $curlopts[\CURLOPT_HEADEROPT] = \CURLHEADER_SEPARATE;
  137.         }
  138.         // curl's resolve feature varies by host:port but ours varies by host only, let's handle this with our own DNS map
  139.         if (isset($this->multi->dnsCache->hostnames[$host])) {
  140.             $options['resolve'] += [$host => $this->multi->dnsCache->hostnames[$host]];
  141.         }
  142.         if ($options['resolve'] || $this->multi->dnsCache->evictions) {
  143.             // First reset any old DNS cache entries then add the new ones
  144.             $resolve $this->multi->dnsCache->evictions;
  145.             $this->multi->dnsCache->evictions = [];
  146.             if ($resolve && 0x072A00 CurlClientState::$curlVersion['version_number']) {
  147.                 // DNS cache removals require curl 7.42 or higher
  148.                 $this->multi->reset();
  149.             }
  150.             foreach ($options['resolve'] as $host => $ip) {
  151.                 $resolve[] = null === $ip "-$host:$port"$host:$port:$ip";
  152.                 $this->multi->dnsCache->hostnames[$host] = $ip;
  153.                 $this->multi->dnsCache->removals["-$host:$port"] = "-$host:$port";
  154.             }
  155.             $curlopts[\CURLOPT_RESOLVE] = $resolve;
  156.         }
  157.         if ('POST' === $method) {
  158.             // Use CURLOPT_POST to have browser-like POST-to-GET redirects for 301, 302 and 303
  159.             $curlopts[\CURLOPT_POST] = true;
  160.         } elseif ('HEAD' === $method) {
  161.             $curlopts[\CURLOPT_NOBODY] = true;
  162.         } else {
  163.             $curlopts[\CURLOPT_CUSTOMREQUEST] = $method;
  164.         }
  165.         if ('\\' !== \DIRECTORY_SEPARATOR && $options['timeout'] < 1) {
  166.             $curlopts[\CURLOPT_NOSIGNAL] = true;
  167.         }
  168.         if (\extension_loaded('zlib') && !isset($options['normalized_headers']['accept-encoding'])) {
  169.             $options['headers'][] = 'Accept-Encoding: gzip'// Expose only one encoding, some servers mess up when more are provided
  170.         }
  171.         $body $options['body'];
  172.         foreach ($options['headers'] as $i => $header) {
  173.             if (\is_string($body) && '' !== $body && === stripos($header'Content-Length: ')) {
  174.                 // Let curl handle Content-Length headers
  175.                 unset($options['headers'][$i]);
  176.                 continue;
  177.             }
  178.             if (':' === $header[-2] && \strlen($header) - === strpos($header': ')) {
  179.                 // curl requires a special syntax to send empty headers
  180.                 $curlopts[\CURLOPT_HTTPHEADER][] = substr_replace($header';', -2);
  181.             } else {
  182.                 $curlopts[\CURLOPT_HTTPHEADER][] = $header;
  183.             }
  184.         }
  185.         // Prevent curl from sending its default Accept and Expect headers
  186.         foreach (['accept''expect'] as $header) {
  187.             if (!isset($options['normalized_headers'][$header][0])) {
  188.                 $curlopts[\CURLOPT_HTTPHEADER][] = $header.':';
  189.             }
  190.         }
  191.         if (!\is_string($body)) {
  192.             if (\is_resource($body)) {
  193.                 $curlopts[\CURLOPT_INFILE] = $body;
  194.             } else {
  195.                 $eof false;
  196.                 $buffer '';
  197.                 $curlopts[\CURLOPT_READFUNCTION] = static function ($ch$fd$length) use ($body, &$buffer, &$eof) {
  198.                     return self::readRequestBody($length$body$buffer$eof);
  199.                 };
  200.             }
  201.             if (isset($options['normalized_headers']['content-length'][0])) {
  202.                 $curlopts[\CURLOPT_INFILESIZE] = (int) substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
  203.             }
  204.             if (!isset($options['normalized_headers']['transfer-encoding'])) {
  205.                 $curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding:'.(isset($curlopts[\CURLOPT_INFILESIZE]) ? '' ' chunked');
  206.             }
  207.             if ('POST' !== $method) {
  208.                 $curlopts[\CURLOPT_UPLOAD] = true;
  209.                 if (!isset($options['normalized_headers']['content-type']) && !== ($curlopts[\CURLOPT_INFILESIZE] ?? null)) {
  210.                     $curlopts[\CURLOPT_HTTPHEADER][] = 'Content-Type: application/x-www-form-urlencoded';
  211.                 }
  212.             }
  213.         } elseif ('' !== $body || 'POST' === $method) {
  214.             $curlopts[\CURLOPT_POSTFIELDS] = $body;
  215.         }
  216.         if ($options['peer_fingerprint']) {
  217.             if (!isset($options['peer_fingerprint']['pin-sha256'])) {
  218.                 throw new TransportException(__CLASS__.' supports only "pin-sha256" fingerprints.');
  219.             }
  220.             $curlopts[\CURLOPT_PINNEDPUBLICKEY] = 'sha256//'.implode(';sha256//'$options['peer_fingerprint']['pin-sha256']);
  221.         }
  222.         if ($options['bindto']) {
  223.             if (file_exists($options['bindto'])) {
  224.                 $curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
  225.             } elseif (!str_starts_with($options['bindto'], 'if!') && preg_match('/^(.*):(\d+)$/'$options['bindto'], $matches)) {
  226.                 $curlopts[\CURLOPT_INTERFACE] = $matches[1];
  227.                 $curlopts[\CURLOPT_LOCALPORT] = $matches[2];
  228.             } else {
  229.                 $curlopts[\CURLOPT_INTERFACE] = $options['bindto'];
  230.             }
  231.         }
  232.         if ($options['max_duration']) {
  233.             $curlopts[\CURLOPT_TIMEOUT_MS] = 1000 $options['max_duration'];
  234.         }
  235.         if (!empty($options['extra']['curl']) && \is_array($options['extra']['curl'])) {
  236.             $this->validateExtraCurlOptions($options['extra']['curl']);
  237.             $curlopts += $options['extra']['curl'];
  238.         }
  239.         if ($pushedResponse $this->multi->pushedResponses[$url] ?? null) {
  240.             unset($this->multi->pushedResponses[$url]);
  241.             if (self::acceptPushForRequest($method$options$pushedResponse)) {
  242.                 $this->logger?->debug(sprintf('Accepting pushed response: "%s %s"'$method$url));
  243.                 // Reinitialize the pushed response with request's options
  244.                 $ch $pushedResponse->handle;
  245.                 $pushedResponse $pushedResponse->response;
  246.                 $pushedResponse->__construct($this->multi$url$options$this->logger);
  247.             } else {
  248.                 $this->logger?->debug(sprintf('Rejecting pushed response: "%s"'$url));
  249.                 $pushedResponse null;
  250.             }
  251.         }
  252.         if (!$pushedResponse) {
  253.             $ch curl_init();
  254.             $this->logger?->info(sprintf('Request: "%s %s"'$method$url));
  255.             $curlopts += [\CURLOPT_SHARE => $this->multi->share];
  256.         }
  257.         foreach ($curlopts as $opt => $value) {
  258.             if (null !== $value && !curl_setopt($ch$opt$value) && \CURLOPT_CERTINFO !== $opt && (!\defined('CURLOPT_HEADEROPT') || \CURLOPT_HEADEROPT !== $opt)) {
  259.                 $constantName $this->findConstantName($opt);
  260.                 throw new TransportException(sprintf('Curl option "%s" is not supported.'$constantName ?? $opt));
  261.             }
  262.         }
  263.         return $pushedResponse ?? new CurlResponse($this->multi$ch$options$this->logger$methodself::createRedirectResolver($options$host$port), CurlClientState::$curlVersion['version_number'], $url);
  264.     }
  265.     /**
  266.      * {@inheritdoc}
  267.      */
  268.     public function stream(ResponseInterface|iterable $responsesfloat $timeout null): ResponseStreamInterface
  269.     {
  270.         if ($responses instanceof CurlResponse) {
  271.             $responses = [$responses];
  272.         }
  273.         if ($this->multi->handle instanceof \CurlMultiHandle) {
  274.             $active 0;
  275.             while (\CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->multi->handle$active)) {
  276.             }
  277.         }
  278.         return new ResponseStream(CurlResponse::stream($responses$timeout));
  279.     }
  280.     public function reset()
  281.     {
  282.         $this->multi->reset();
  283.     }
  284.     /**
  285.      * Accepts pushed responses only if their headers related to authentication match the request.
  286.      */
  287.     private static function acceptPushForRequest(string $method, array $optionsPushedResponse $pushedResponse): bool
  288.     {
  289.         if ('' !== $options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) {
  290.             return false;
  291.         }
  292.         foreach (['proxy''no_proxy''bindto''local_cert''local_pk'] as $k) {
  293.             if ($options[$k] !== $pushedResponse->parentOptions[$k]) {
  294.                 return false;
  295.             }
  296.         }
  297.         foreach (['authorization''cookie''range''proxy-authorization'] as $k) {
  298.             $normalizedHeaders $options['normalized_headers'][$k] ?? [];
  299.             foreach ($normalizedHeaders as $i => $v) {
  300.                 $normalizedHeaders[$i] = substr($v\strlen($k) + 2);
  301.             }
  302.             if (($pushedResponse->requestHeaders[$k] ?? []) !== $normalizedHeaders) {
  303.                 return false;
  304.             }
  305.         }
  306.         return true;
  307.     }
  308.     /**
  309.      * Wraps the request's body callback to allow it to return strings longer than curl requested.
  310.      */
  311.     private static function readRequestBody(int $length\Closure $bodystring &$bufferbool &$eof): string
  312.     {
  313.         if (!$eof && \strlen($buffer) < $length) {
  314.             if (!\is_string($data $body($length))) {
  315.                 throw new TransportException(sprintf('The return value of the "body" option callback must be a string, "%s" returned.'get_debug_type($data)));
  316.             }
  317.             $buffer .= $data;
  318.             $eof '' === $data;
  319.         }
  320.         $data substr($buffer0$length);
  321.         $buffer substr($buffer$length);
  322.         return $data;
  323.     }
  324.     /**
  325.      * Resolves relative URLs on redirects and deals with authentication headers.
  326.      *
  327.      * Work around CVE-2018-1000007: Authorization and Cookie headers should not follow redirects - fixed in Curl 7.64
  328.      */
  329.     private static function createRedirectResolver(array $optionsstring $hostint $port): \Closure
  330.     {
  331.         $redirectHeaders = [];
  332.         if ($options['max_redirects']) {
  333.             $redirectHeaders['host'] = $host;
  334.             $redirectHeaders['port'] = $port;
  335.             $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = array_filter($options['headers'], static function ($h) {
  336.                 return !== stripos($h'Host:');
  337.             });
  338.             if (isset($options['normalized_headers']['authorization'][0]) || isset($options['normalized_headers']['cookie'][0])) {
  339.                 $redirectHeaders['no_auth'] = array_filter($options['headers'], static function ($h) {
  340.                     return !== stripos($h'Authorization:') && !== stripos($h'Cookie:');
  341.                 });
  342.             }
  343.         }
  344.         return static function ($chstring $locationbool $noContent) use (&$redirectHeaders) {
  345.             try {
  346.                 $location self::parseUrl($location);
  347.             } catch (InvalidArgumentException) {
  348.                 return null;
  349.             }
  350.             if ($noContent && $redirectHeaders) {
  351.                 $filterContentHeaders = static function ($h) {
  352.                     return !== stripos($h'Content-Length:') && !== stripos($h'Content-Type:') && !== stripos($h'Transfer-Encoding:');
  353.                 };
  354.                 $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);
  355.                 $redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders);
  356.             }
  357.             if ($redirectHeaders && $host parse_url('http:'.$location['authority'], \PHP_URL_HOST)) {
  358.                 $port parse_url('http:'.$location['authority'], \PHP_URL_PORT) ?: ('http:' === $location['scheme'] ? 80 443);
  359.                 $requestHeaders $redirectHeaders['host'] === $host && $redirectHeaders['port'] === $port $redirectHeaders['with_auth'] : $redirectHeaders['no_auth'];
  360.                 curl_setopt($ch\CURLOPT_HTTPHEADER$requestHeaders);
  361.             } elseif ($noContent && $redirectHeaders) {
  362.                 curl_setopt($ch\CURLOPT_HTTPHEADER$redirectHeaders['with_auth']);
  363.             }
  364.             $url self::parseUrl(curl_getinfo($ch\CURLINFO_EFFECTIVE_URL));
  365.             $url self::resolveUrl($location$url);
  366.             curl_setopt($ch\CURLOPT_PROXY$options['proxy']
  367.                 ?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null null)
  368.                 // Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
  369.                 ?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli''phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null
  370.             );
  371.             return implode(''$url);
  372.         };
  373.     }
  374.     private function findConstantName(int $opt): ?string
  375.     {
  376.         $constants array_filter(get_defined_constants(), static function ($v$k) use ($opt) {
  377.             return $v === $opt && 'C' === $k[0] && (str_starts_with($k'CURLOPT_') || str_starts_with($k'CURLINFO_'));
  378.         }, \ARRAY_FILTER_USE_BOTH);
  379.         return key($constants);
  380.     }
  381.     /**
  382.      * Prevents overriding options that are set internally throughout the request.
  383.      */
  384.     private function validateExtraCurlOptions(array $options): void
  385.     {
  386.         $curloptsToConfig = [
  387.             // options used in CurlHttpClient
  388.             \CURLOPT_HTTPAUTH => 'auth_ntlm',
  389.             \CURLOPT_USERPWD => 'auth_ntlm',
  390.             \CURLOPT_RESOLVE => 'resolve',
  391.             \CURLOPT_NOSIGNAL => 'timeout',
  392.             \CURLOPT_HTTPHEADER => 'headers',
  393.             \CURLOPT_INFILE => 'body',
  394.             \CURLOPT_READFUNCTION => 'body',
  395.             \CURLOPT_INFILESIZE => 'body',
  396.             \CURLOPT_POSTFIELDS => 'body',
  397.             \CURLOPT_UPLOAD => 'body',
  398.             \CURLOPT_INTERFACE => 'bindto',
  399.             \CURLOPT_TIMEOUT_MS => 'max_duration',
  400.             \CURLOPT_TIMEOUT => 'max_duration',
  401.             \CURLOPT_MAXREDIRS => 'max_redirects',
  402.             \CURLOPT_PROXY => 'proxy',
  403.             \CURLOPT_NOPROXY => 'no_proxy',
  404.             \CURLOPT_SSL_VERIFYPEER => 'verify_peer',
  405.             \CURLOPT_SSL_VERIFYHOST => 'verify_host',
  406.             \CURLOPT_CAINFO => 'cafile',
  407.             \CURLOPT_CAPATH => 'capath',
  408.             \CURLOPT_SSL_CIPHER_LIST => 'ciphers',
  409.             \CURLOPT_SSLCERT => 'local_cert',
  410.             \CURLOPT_SSLKEY => 'local_pk',
  411.             \CURLOPT_KEYPASSWD => 'passphrase',
  412.             \CURLOPT_CERTINFO => 'capture_peer_cert_chain',
  413.             \CURLOPT_USERAGENT => 'normalized_headers',
  414.             \CURLOPT_REFERER => 'headers',
  415.             // options used in CurlResponse
  416.             \CURLOPT_NOPROGRESS => 'on_progress',
  417.             \CURLOPT_PROGRESSFUNCTION => 'on_progress',
  418.         ];
  419.         if (\defined('CURLOPT_UNIX_SOCKET_PATH')) {
  420.             $curloptsToConfig[\CURLOPT_UNIX_SOCKET_PATH] = 'bindto';
  421.         }
  422.         if (\defined('CURLOPT_PINNEDPUBLICKEY')) {
  423.             $curloptsToConfig[\CURLOPT_PINNEDPUBLICKEY] = 'peer_fingerprint';
  424.         }
  425.         $curloptsToCheck = [
  426.             \CURLOPT_PRIVATE,
  427.             \CURLOPT_HEADERFUNCTION,
  428.             \CURLOPT_WRITEFUNCTION,
  429.             \CURLOPT_VERBOSE,
  430.             \CURLOPT_STDERR,
  431.             \CURLOPT_RETURNTRANSFER,
  432.             \CURLOPT_URL,
  433.             \CURLOPT_FOLLOWLOCATION,
  434.             \CURLOPT_HEADER,
  435.             \CURLOPT_CONNECTTIMEOUT,
  436.             \CURLOPT_CONNECTTIMEOUT_MS,
  437.             \CURLOPT_HTTP_VERSION,
  438.             \CURLOPT_PORT,
  439.             \CURLOPT_DNS_USE_GLOBAL_CACHE,
  440.             \CURLOPT_PROTOCOLS,
  441.             \CURLOPT_REDIR_PROTOCOLS,
  442.             \CURLOPT_COOKIEFILE,
  443.             \CURLINFO_REDIRECT_COUNT,
  444.         ];
  445.         if (\defined('CURLOPT_HTTP09_ALLOWED')) {
  446.             $curloptsToCheck[] = \CURLOPT_HTTP09_ALLOWED;
  447.         }
  448.         if (\defined('CURLOPT_HEADEROPT')) {
  449.             $curloptsToCheck[] = \CURLOPT_HEADEROPT;
  450.         }
  451.         $methodOpts = [
  452.             \CURLOPT_POST,
  453.             \CURLOPT_PUT,
  454.             \CURLOPT_CUSTOMREQUEST,
  455.             \CURLOPT_HTTPGET,
  456.             \CURLOPT_NOBODY,
  457.         ];
  458.         foreach ($options as $opt => $optValue) {
  459.             if (isset($curloptsToConfig[$opt])) {
  460.                 $constName $this->findConstantName($opt) ?? $opt;
  461.                 throw new InvalidArgumentException(sprintf('Cannot set "%s" with "extra.curl", use option "%s" instead.'$constName$curloptsToConfig[$opt]));
  462.             }
  463.             if (\in_array($opt$methodOpts)) {
  464.                 throw new InvalidArgumentException('The HTTP method cannot be overridden using "extra.curl".');
  465.             }
  466.             if (\in_array($opt$curloptsToCheck)) {
  467.                 $constName $this->findConstantName($opt) ?? $opt;
  468.                 throw new InvalidArgumentException(sprintf('Cannot set "%s" with "extra.curl".'$constName));
  469.             }
  470.         }
  471.     }
  472. }