Commit 23a99466dc15b7a956aba444e107e6a1c560de98
1 parent
d6d40c1d
Exists in
master
and in
109 other branches
Fix proxy host definition
Showing
2 changed files
with
16 additions
and
11 deletions
Show diff stats
php/classes/ProxyUtils.php
... | ... | @@ -2,16 +2,19 @@ |
2 | 2 | |
3 | 3 | class ProxyUtils { |
4 | 4 | static function addProxyForCurl(&$ch) { |
5 | - if (defined('PROXY_HOST')) { | |
6 | - curl_setopt($ch, CURLOPT_PROXY, "http://".PROXY_HOST); | |
7 | - if (defined('PROXY_USERPWD')) { | |
8 | - curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USERPWD); | |
5 | + $proxy_host = PROXY_HOST; | |
6 | + if (!empty($proxy_host)) { | |
7 | + curl_setopt($ch, CURLOPT_PROXY, "http://".$proxy_host); | |
8 | + $proxy_userpwd = PROXY_USERPWD; | |
9 | + if (!empty($proxy_userpwd)) { | |
10 | + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpwd); | |
9 | 11 | } |
10 | 12 | } |
11 | 13 | } |
12 | 14 | |
13 | 15 | static function getStreamContextWithProxy() { |
14 | - if (!defined('PROXY_HOST')) | |
16 | + $proxy_host = PROXY_HOST; | |
17 | + if (empty($proxy_host)) | |
15 | 18 | return; |
16 | 19 | $options = array( |
17 | 20 | 'http' => array( |
... | ... | @@ -21,10 +24,11 @@ class ProxyUtils { |
21 | 24 | 'ignore_errors' => true, |
22 | 25 | ) |
23 | 26 | ); |
24 | - $options['http']['proxy'] = 'tcp://'.PROXY_HOST; | |
27 | + $options['http']['proxy'] = 'tcp://'.$proxy_host; | |
25 | 28 | $options['http']['request_fulluri'] = TRUE; |
26 | - if (defined('PROXY_USERPWD')) { | |
27 | - $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode(PROXY_USERPWD); | |
29 | + $proxy_userpwd = PROXY_USERPWD; | |
30 | + if (!empty($proxy_userpwd)) { | |
31 | + $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode($proxy_userpwd); | |
28 | 32 | } |
29 | 33 | return stream_context_create($options); |
30 | 34 | } | ... | ... |
php/epntap.php
... | ... | @@ -64,13 +64,14 @@ function resolver() { |
64 | 64 | } |
65 | 65 | |
66 | 66 | function request($access_url, $query) { |
67 | - error_log($query); | |
67 | +# error_log($query); | |
68 | 68 | $votMgr = new VOTableMgr; |
69 | 69 | $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery'; |
70 | 70 | $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode(preg_replace('/\s+/', ' ', $query)); // remove also multiple whitespaces |
71 | 71 | |
72 | - $votMgr->load($url); | |
73 | - $data = $votMgr->parseStream(); | |
72 | + if ($votMgr->load($url)) { | |
73 | + $data = $votMgr->parseStream(); | |
74 | + } | |
74 | 75 | $error = $votMgr->getVotableError(); |
75 | 76 | |
76 | 77 | $response = ['query' => $query, 'metaData' => ['root' => 'data', 'messageProperty' => 'msg']]; | ... | ... |