Skip to content

Commit f68e20d

Browse files
committed
feat: added options fresh_connect to CURLRequest
1 parent f7d6142 commit f68e20d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

system/HTTP/CURLRequest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ public function send(string $method, string $url)
365365
$curlOptions[CURLOPT_URL] = $url;
366366
$curlOptions[CURLOPT_RETURNTRANSFER] = true;
367367
$curlOptions[CURLOPT_HEADER] = true;
368-
$curlOptions[CURLOPT_FRESH_CONNECT] = true;
369368
// Disable @file uploads in post data.
370369
$curlOptions[CURLOPT_SAFE_UPLOAD] = true;
371370

@@ -621,6 +620,11 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
621620
$curlOptions[CURLOPT_DNS_CACHE_TIMEOUT] = (int) $config['dns_cache_timeout'];
622621
}
623622

623+
// Fresh Connect (default true)
624+
$curlOptions[CURLOPT_FRESH_CONNECT] = isset($config['fresh_connect']) && is_bool($config['fresh_connect'])
625+
? $config['fresh_connect']
626+
: true;
627+
624628
// Timeout
625629
$curlOptions[CURLOPT_TIMEOUT_MS] = (float) $config['timeout'] * 1000;
626630

tests/system/HTTP/CURLRequestTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,28 @@ public function testProxyuOption(): void
583583
$this->assertTrue($options[CURLOPT_HTTPPROXYTUNNEL]);
584584
}
585585

586+
public function testFreshConnectDefault(): void
587+
{
588+
$this->request->request('get', 'http://example.com');
589+
590+
$options = $this->request->curl_options;
591+
592+
$this->assertArrayHasKey(CURLOPT_FRESH_CONNECT, $options);
593+
$this->assertTrue($options[CURLOPT_FRESH_CONNECT]);
594+
}
595+
596+
public function testFreshConnectFalseOption(): void
597+
{
598+
$this->request->request('get', 'http://example.com', [
599+
'fresh_connect' => false,
600+
]);
601+
602+
$options = $this->request->curl_options;
603+
604+
$this->assertArrayHasKey(CURLOPT_FRESH_CONNECT, $options);
605+
$this->assertFalse($options[CURLOPT_FRESH_CONNECT]);
606+
}
607+
586608
public function testDebugOptionTrue(): void
587609
{
588610
$this->request->request('get', 'http://example.com', [

0 commit comments

Comments
 (0)