Skip to content

Commit bd90774

Browse files
authored
Merge pull request #185 from msnassar/master
Support for proxy on curl request
2 parents 37d938f + fc41c81 commit bd90774

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ JIRA_PASS="jira-password-OR-api-token"
6666
# to enable session cookie authorization
6767
# COOKIE_AUTH_ENABLED=true
6868
# COOKIE_FILE=storage/jira-cookie.txt
69+
# if you are behind a proxy, add proxy settings
70+
PROXY_SERVER="your-proxy-server"
71+
PROXY_PORT="proxy-port"
72+
PROXY_USER="proxy-username"
73+
PROXY_PASSWORD="proxy-password"
6974
```
7075

7176
**Important Note:**
@@ -92,6 +97,11 @@ $iss = new IssueService(new ArrayConfiguration(
9297
// to enable session cookie authorization (with basic authorization only)
9398
'cookieAuthEnabled' => true,
9499
'cookieFile' => storage_path('jira-cookie.txt'),
100+
// if you are behind a proxy, add proxy settings
101+
"proxyServer" => 'your-proxy-server',
102+
"proxyPort" => 'proxy-port',
103+
"proxyUser" => 'proxy-username',
104+
"proxyPassword" => 'proxy-password',
95105
)
96106
));
97107
```

src/Configuration/AbstractConfiguration.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,34 @@ abstract class AbstractConfiguration implements ConfigurationInterface
9191
*/
9292
protected $cookieFile;
9393

94+
/**
95+
* Proxy server.
96+
*
97+
* @var string
98+
*/
99+
protected $proxyServer;
100+
101+
/**
102+
* Proxy port.
103+
*
104+
* @var string
105+
*/
106+
protected $proxyPort;
107+
108+
/**
109+
* Proxy user.
110+
*
111+
* @var string
112+
*/
113+
protected $proxyUser;
114+
115+
/**
116+
* Proxy password.
117+
*
118+
* @var string
119+
*/
120+
protected $proxyPassword;
121+
94122
/**
95123
* @return string
96124
*/
@@ -200,4 +228,36 @@ public function getCookieFile()
200228
{
201229
return $this->cookieFile;
202230
}
231+
232+
/**
233+
* @return string
234+
*/
235+
public function getProxyServer()
236+
{
237+
return $this->proxyServer;
238+
}
239+
240+
/**
241+
* @return string
242+
*/
243+
public function getProxyPort()
244+
{
245+
return $this->proxyPort;
246+
}
247+
248+
/**
249+
* @return string
250+
*/
251+
public function getProxyUser()
252+
{
253+
return $this->proxyUser;
254+
}
255+
256+
/**
257+
* @return string
258+
*/
259+
public function getProxyPassword()
260+
{
261+
return $this->proxyPassword;
262+
}
203263
}

src/Configuration/ConfigurationInterface.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,32 @@ public function isCookieAuthorizationEnabled();
9696
* @return mixed
9797
*/
9898
public function getCookieFile();
99+
100+
/**
101+
* Proxy server.
102+
*
103+
* @return string
104+
*/
105+
public function getProxyServer();
106+
107+
/**
108+
* Proxy port.
109+
*
110+
* @return string
111+
*/
112+
public function getProxyPort();
113+
114+
/**
115+
* Proxy user.
116+
*
117+
* @return string
118+
*/
119+
public function getProxyUser();
120+
121+
/**
122+
* Proxy password.
123+
*
124+
* @return string
125+
*/
126+
public function getProxyPassword();
99127
}

src/Configuration/DotEnvConfiguration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function __construct($path = '.')
4141
$this->curlOptSslVerifyPeer = $this->env('CURLOPT_SSL_VERIFYPEER', false);
4242
$this->curlOptUserAgent = $this->env('CURLOPT_USERAGENT', $this->getDefaultUserAgentString());
4343
$this->curlOptVerbose = $this->env('CURLOPT_VERBOSE', false);
44+
$this->proxyServer = $this->env('PROXY_SERVER');
45+
$this->proxyPort = $this->env('PROXY_PORT');
46+
$this->proxyUser = $this->env('PROXY_USER');
47+
$this->proxyPassword = $this->env('PROXY_PASSWORD');
4448
}
4549

4650
/**

src/JiraClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ public function exec($context, $post_data = null, $custom_request = null, $cooki
208208

209209
curl_setopt($ch, CURLOPT_VERBOSE, $this->getConfiguration()->isCurlOptVerbose());
210210

211+
// Add proxy settings to the curl.
212+
if ($this->getConfiguration()->getProxyServer()) {
213+
curl_setopt($ch, CURLOPT_PROXY, $this->getConfiguration()->getProxyServer());
214+
curl_setopt($ch, CURLOPT_PROXYPORT, $this->getConfiguration()->getProxyPort());
215+
216+
$username = $this->getConfiguration()->getProxyUser();
217+
$password = $this->getConfiguration()->getProxyPassword();
218+
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$username:$password");
219+
}
220+
211221
$this->log->addDebug('Curl exec='.$url);
212222
$response = curl_exec($ch);
213223

0 commit comments

Comments
 (0)