Skip to content

Commit

Permalink
setProxy method for CurlHttpClient for BC
Browse files Browse the repository at this point in the history
  • Loading branch information
BoShurik committed Sep 26, 2023
1 parent 64a9b86 commit 8265aa7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Http/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,29 @@ private static function curlValidate($curl, $response = null)
}
}

/**
* Enable proxy for curl requests. Empty string will disable proxy.
*
* @param string $proxyString
* @param bool $socks5
* @return void
*/
public function setProxy($proxyString = '', $socks5 = false)
{
if (empty($proxyString)) {
unset($this->options[CURLOPT_PROXY], $this->options[CURLOPT_HTTPPROXYTUNNEL], $this->options[CURLOPT_PROXYTYPE]);

return;
}

$this->options[CURLOPT_PROXY] = $proxyString;
$this->options[CURLOPT_HTTPPROXYTUNNEL] = true;

if ($socks5) {
$this->options[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5;
}
}

/**
* @param string $option
* @param string|int|bool $value
Expand Down

0 comments on commit 8265aa7

Please sign in to comment.