|
17 | 17 | use CodeIgniter\HTTP\Exceptions\HTTPException;
|
18 | 18 | use Config\App;
|
19 | 19 | use Config\CURLRequest as ConfigCURLRequest;
|
| 20 | +use CurlShareHandle; |
20 | 21 |
|
21 | 22 | /**
|
22 | 23 | * A lightweight HTTP client for sending synchronous HTTP requests via cURL.
|
@@ -101,6 +102,14 @@ class CURLRequest extends OutgoingRequest
|
101 | 102 | */
|
102 | 103 | private readonly bool $shareOptions;
|
103 | 104 |
|
| 105 | + /** |
| 106 | + * Whether share options between requests or not. |
| 107 | + * |
| 108 | + * If true, all the options won't be reset between requests. |
| 109 | + * It may cause an error request with unnecessary headers. |
| 110 | + */ |
| 111 | + private readonly CurlShareHandle $shareConnection; |
| 112 | + |
104 | 113 | /**
|
105 | 114 | * Takes an array of options to set the following possible class properties:
|
106 | 115 | *
|
@@ -129,6 +138,11 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response
|
129 | 138 |
|
130 | 139 | $this->config = $this->defaultConfig;
|
131 | 140 | $this->parseOptions($options);
|
| 141 | + |
| 142 | + // Share Connection |
| 143 | + $this->shareConnection = curl_share_init(); |
| 144 | + curl_share_setopt($this->shareConnection, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); |
| 145 | + curl_share_setopt($this->shareConnection, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); |
132 | 146 | }
|
133 | 147 |
|
134 | 148 | /**
|
@@ -363,6 +377,7 @@ public function send(string $method, string $url)
|
363 | 377 | }
|
364 | 378 |
|
365 | 379 | $curlOptions[CURLOPT_URL] = $url;
|
| 380 | + $curlOptions[CURLOPT_SHARE] = $this->shareConnection; |
366 | 381 | $curlOptions[CURLOPT_RETURNTRANSFER] = true;
|
367 | 382 | $curlOptions[CURLOPT_HEADER] = true;
|
368 | 383 | // Disable @file uploads in post data.
|
|
0 commit comments