Skip to content

Commit faa9891

Browse files
committed
feat: added options fresh_connect to CURLRequest
1 parent ac89c61 commit faa9891

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

@@ -616,6 +615,11 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
616615
}
617616
}
618617

618+
// Fresh Connect (default true)
619+
$curlOptions[CURLOPT_FRESH_CONNECT] = isset($config['fresh_connect']) && is_bool($config['fresh_connect'])
620+
? $config['fresh_connect']
621+
: true;
622+
619623
// Timeout
620624
$curlOptions[CURLOPT_TIMEOUT_MS] = (float) $config['timeout'] * 1000;
621625

tests/system/HTTP/CURLRequestTest.php

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

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

0 commit comments

Comments
 (0)