Skip to content

Commit

Permalink
Merge pull request #7632 from kenjis/feat-curlrequest-proxy
Browse files Browse the repository at this point in the history
feat: [CURLRequest] add option for Proxy
  • Loading branch information
kenjis authored Jun 29, 2023
2 parents d9c7f06 + 35d7d29 commit b241ca8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
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
3 changes: 2 additions & 1 deletion user_guide_src/source/changelogs/v4.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ Libraries
- **Validation:** Added ``Validation::getValidated()`` method that gets
the actual validated data. See :ref:`validation-getting-validated-data` for details.
- **Images:** The option ``$quality`` can now be used to compress WebP images.

- **Uploaded Files:** Added ``UploadedFiles::getClientPath()`` method that returns
the value of the `full_path` index of the file if it was uploaded via directory upload.
- **CURLRequest:** Added a request option ``proxy``. See
:ref:`CURLRequest Class <curlrequest-request-options-proxy>`.

Helpers and Functions
=====================
Expand Down
11 changes: 11 additions & 0 deletions user_guide_src/source/libraries/curlrequest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,17 @@ has been disabled. Any files that you want to send must be passed as instances o
``form_params`` for ``application/x-www-form-urlencoded`` requests, and ``multipart`` for ``multipart/form-data``
requests.

.. _curlrequest-request-options-proxy:

proxy
=====

.. versionadded:: 4.4.0

You can set a proxy by passing an associative array as the ``proxy`` option:

.. literalinclude:: curlrequest/035.php

query
=====

Expand Down
7 changes: 7 additions & 0 deletions user_guide_src/source/libraries/curlrequest/035.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

$client->request(
'GET',
'http://example.com',
['proxy' => 'http://localhost:3128']
);

0 comments on commit b241ca8

Please sign in to comment.