diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-10-08 20:54:07 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-10-08 20:54:07 -0400 |
commit | 586c600040123642a18ae77571d9414860a338f4 (patch) | |
tree | 36145409edaf3fb280eec78338c116328a65f8cd /app/Core | |
parent | 546e6fe7428b5bdd045ae57c4c5a6b729508a4e8 (diff) |
Add proxy support for http client
Diffstat (limited to 'app/Core')
-rw-r--r-- | app/Core/HttpClient.php | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/app/Core/HttpClient.php b/app/Core/HttpClient.php index b808f756..99534cfe 100644 --- a/app/Core/HttpClient.php +++ b/app/Core/HttpClient.php @@ -99,9 +99,18 @@ class HttpClient extends Base return ''; } - $headers = array_merge(array('User-Agent: '.self::HTTP_USER_AGENT, 'Connection: close'), $headers); + $default_headers = array( + 'User-Agent: '.self::HTTP_USER_AGENT, + 'Connection: close', + ); + + if (HTTP_PROXY_USERNAME) { + $default_headers[] = 'Proxy-Authorization: Basic '.base64_encode(HTTP_PROXY_USERNAME.':'.HTTP_PROXY_PASSWORD); + } + + $headers = array_merge($default_headers, $headers); - $context = stream_context_create(array( + $context = array( 'http' => array( 'method' => $method, 'protocol_version' => 1.1, @@ -110,9 +119,14 @@ class HttpClient extends Base 'header' => implode("\r\n", $headers), 'content' => $content ) - )); + ); + + if (HTTP_PROXY_HOSTNAME) { + $context['http']['proxy'] = 'tcp://'.HTTP_PROXY_HOSTNAME.':'.HTTP_PROXY_PORT; + $context['http']['request_fulluri'] = true; + } - $stream = @fopen(trim($url), 'r', false, $context); + $stream = @fopen(trim($url), 'r', false, stream_context_create($context)); $response = ''; if (is_resource($stream)) { |