From 04bcb1951d42d8238d4924ff62a232f4be488f9b Mon Sep 17 00:00:00 2001 From: Quentin Fahrner Date: Mon, 21 Jan 2019 10:42:59 +1100 Subject: [PATCH] Proxy support for API calls This PR fixes issue https://github.com/campaignmonitor/createsend-php/issues/22 --- class/transport.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/class/transport.php b/class/transport.php index 5c64c3f..43378ff 100644 --- a/class/transport.php +++ b/class/transport.php @@ -10,6 +10,15 @@ if (false === defined('CS_REST_CALL_TIMEOUT')) { define('CS_REST_CALL_TIMEOUT', 20); } +if (false === defined('CS_REST_PROXY')) { + define('CS_REST_PROXY', ''); +} +if (false === defined('CS_REST_PROXY_PORT')) { + define('CS_REST_PROXY_PORT', ''); +} +if (false === defined('CS_REST_NO_PROXY')) { + define('CS_REST_NO_PROXY', ''); +} if(!function_exists("CS_REST_TRANSPORT_get_available")) { function CS_REST_TRANSPORT_get_available($requires_ssl, $log) { @@ -164,6 +173,11 @@ function make_call($call_options) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } + // Add proxy settings. + curl_setopt($ch, CURLOPT_PROXY, CS_REST_PROXY); + curl_setopt($ch, CURLOPT_PROXYPORT, CS_REST_PROXY_PORT); + curl_setopt($ch, CURLOPT_NOPROXY, CS_REST_NO_PROXY); + $response = curl_exec($ch); if(!$response && $response !== '') { @@ -349,4 +363,4 @@ function _build_request($call_options, $host, $path, $accept_gzip) { return $request."\n\n"; } } -} \ No newline at end of file +}