Skip to content

Commit

Permalink
feat: add request option proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jun 28, 2023
1 parent d19d034 commit 8c6e883
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,12 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
}
}

// Proxy
if (isset($config['proxy'])) {
$curlOptions[CURLOPT_HTTPPROXYTUNNEL] = true;
$curlOptions[CURLOPT_PROXY] = $config['proxy'];
}

// Debug
if ($config['debug']) {
$curlOptions[CURLOPT_VERBOSE] = 1;
Expand Down
14 changes: 14 additions & 0 deletions tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,20 @@ public function testSSLWithBadKey()
]);
}

public function testProxyuOption()
{
$this->request->request('get', 'http://example.com', [
'proxy' => 'http://localhost:3128',
]);

$options = $this->request->curl_options;

$this->assertArrayHasKey(CURLOPT_PROXY, $options);
$this->assertSame('http://localhost:3128', $options[CURLOPT_PROXY]);
$this->assertArrayHasKey(CURLOPT_HTTPPROXYTUNNEL, $options);
$this->assertTrue($options[CURLOPT_HTTPPROXYTUNNEL]);
}

public function testDebugOptionTrue()
{
$this->request->request('get', 'http://example.com', [
Expand Down
14 changes: 14 additions & 0 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,20 @@ public function testSSLWithBadKey()
]);
}

public function testProxyuOption()
{
$this->request->request('get', 'http://example.com', [
'proxy' => 'http://localhost:3128',
]);

$options = $this->request->curl_options;

$this->assertArrayHasKey(CURLOPT_PROXY, $options);
$this->assertSame('http://localhost:3128', $options[CURLOPT_PROXY]);
$this->assertArrayHasKey(CURLOPT_HTTPPROXYTUNNEL, $options);
$this->assertTrue($options[CURLOPT_HTTPPROXYTUNNEL]);
}

public function testDebugOptionTrue()
{
$this->request->request('get', 'http://example.com', [
Expand Down

0 comments on commit 8c6e883

Please sign in to comment.