mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-26 13:27:52 +03:00
make HTTP proxy setup explicit
The setup relies on the project configuration which we want to explicitly set up in later steps. Therefore proxy setup needs to be done explicitly as well. There is the added bonus that the setup is done only for the utils which try to call outside.
This commit is contained in:
parent
b5480f6e36
commit
ac116980ac
28
lib/cmd.php
28
lib/cmd.php
@ -195,3 +195,31 @@ function runSQLScript($sScript, $bfatal = true, $bVerbose = false, $bIgnoreError
|
||||
fail("pgsql returned with error code ($iReturn)");
|
||||
}
|
||||
}
|
||||
|
||||
function setupHTTPProxy()
|
||||
{
|
||||
if (!CONST_HTTP_Proxy) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sProxy = 'tcp://'.CONST_HTTP_Proxy_Host.':'.CONST_HTTP_Proxy_Port;
|
||||
$aHeaders = array();
|
||||
|
||||
if (CONST_HTTP_Proxy_Login != null
|
||||
&& CONST_HTTP_Proxy_Login != ''
|
||||
&& CONST_HTTP_Proxy_Password != null
|
||||
&& CONST_HTTP_Proxy_Password != ''
|
||||
) {
|
||||
$sAuth = base64_encode(CONST_HTTP_Proxy_Login.':'.CONST_HTTP_Proxy_Password);
|
||||
$aHeaders = array('Proxy-Authorization: Basic '.$sAuth);
|
||||
}
|
||||
|
||||
$aProxyHeader = array(
|
||||
'proxy' => $sProxy,
|
||||
'request_fulluri' => true,
|
||||
'header' => $aHeaders
|
||||
);
|
||||
|
||||
$aContext = array('http' => $aProxyHeader, 'https' => $aProxyHeader);
|
||||
stream_context_set_default($aContext);
|
||||
}
|
||||
|
@ -3,26 +3,3 @@
|
||||
require_once('init.php');
|
||||
require_once('cmd.php');
|
||||
require_once('DebugNone.php');
|
||||
|
||||
// handle http proxy when using file_get_contents
|
||||
if (CONST_HTTP_Proxy) {
|
||||
$proxy = 'tcp://' . CONST_HTTP_Proxy_Host . ':' . CONST_HTTP_Proxy_Port;
|
||||
$aHeaders = array();
|
||||
if (CONST_HTTP_Proxy_Login != null && CONST_HTTP_Proxy_Login != '' && CONST_HTTP_Proxy_Password != null && CONST_HTTP_Proxy_Password != '') {
|
||||
$auth = base64_encode(CONST_HTTP_Proxy_Login . ':' . CONST_HTTP_Proxy_Password);
|
||||
$aHeaders = array("Proxy-Authorization: Basic $auth");
|
||||
}
|
||||
$aContext = array(
|
||||
'http' => array(
|
||||
'proxy' => $proxy,
|
||||
'request_fulluri' => true,
|
||||
'header' => $aHeaders
|
||||
),
|
||||
'https' => array(
|
||||
'proxy' => $proxy,
|
||||
'request_fulluri' => true,
|
||||
'header' => $aHeaders
|
||||
)
|
||||
);
|
||||
stream_context_set_default($aContext);
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ $aCMDOptions
|
||||
);
|
||||
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
|
||||
|
||||
setupHTTPProxy();
|
||||
|
||||
include(CONST_Phrase_Config);
|
||||
|
||||
if (true) {
|
||||
|
@ -49,6 +49,8 @@ $aCMDOptions
|
||||
// $aCMDOptions passed to getCmdOpt by reference
|
||||
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
|
||||
|
||||
setupHTTPProxy();
|
||||
|
||||
$bDidSomething = false;
|
||||
|
||||
//*******************************************************
|
||||
|
@ -14,6 +14,8 @@ $aCMDOptions
|
||||
);
|
||||
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
|
||||
|
||||
setupHTTPProxy();
|
||||
|
||||
include(CONST_Phrase_Config);
|
||||
|
||||
if ($aCMDResult['wiki-import']) {
|
||||
|
@ -46,6 +46,8 @@ $aCMDOptions
|
||||
|
||||
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
|
||||
|
||||
setupHTTPProxy();
|
||||
|
||||
if (!isset($aResult['index-instances'])) $aResult['index-instances'] = 1;
|
||||
if (!isset($aResult['index-rank'])) $aResult['index-rank'] = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user