Blame view

php/classes/ProxyUtils.php 1008 Bytes
ba35574d   Benjamin Renard   Uniformize proxy ...
1
2
3
<?php

class ProxyUtils {
f8a74187   Elena.Budnik   case when PROXY_H...
4
5
6
7
8
9
10
11
12
13
14
15
	static function addProxyForCurl(&$ch) {
		if ( defined(PROXY_HOST) ) {
			$proxy_host = PROXY_HOST;
			if (!empty($proxy_host)) {
				curl_setopt($ch, CURLOPT_PROXY, "http://".$proxy_host);
				$proxy_userpwd = PROXY_USERPWD;
				if (!empty($proxy_userpwd)) {
						curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpwd);
				}
			}
		}
	}
ba35574d   Benjamin Renard   Uniformize proxy ...
16

f8a74187   Elena.Budnik   case when PROXY_H...
17
	static function getStreamContextWithProxy() {
9cf77f46   Elena.Budnik   case when PROXY_H...
18
19
		if (!defined(PROXY_HOST))
					return;
f8a74187   Elena.Budnik   case when PROXY_H...
20
		$proxy_host = PROXY_HOST;
9cf77f46   Elena.Budnik   case when PROXY_H...
21
		if (empty($proxy_host))
f8a74187   Elena.Budnik   case when PROXY_H...
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
					return;
		$options = array(
			'http' => array(
					'method' => 'GET',
					'timeout' => '5',
					'user_agent' => 'PHP libxml agent',
					'ignore_errors' => true,
				)
			);
			
		$options['http']['proxy'] = 'tcp://'.$proxy_host;
		$options['http']['request_fulluri'] = TRUE;
		$proxy_userpwd = PROXY_USERPWD;
		if (!empty($proxy_userpwd)) {
			$options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode($proxy_userpwd);
		}
		return stream_context_create($options);
	}
ba35574d   Benjamin Renard   Uniformize proxy ...
40
}
ba35574d   Benjamin Renard   Uniformize proxy ...
41
?>