mirror of
https://github.com/getgrav/grav.git
synced 2026-03-06 12:31:53 +01:00
Allow authentication for proxy
This commit is contained in:
@@ -201,7 +201,15 @@ class Response
|
||||
// if proxy set add that
|
||||
$proxy_url = self::getGrav()['config']->get('system.proxy_url');
|
||||
if ($proxy_url) {
|
||||
$options['fopen']['proxy'] = $proxy_url;
|
||||
$parsed_url = parse_url($proxy_url);
|
||||
|
||||
$options['fopen']['proxy'] = ($parsed_url['scheme'] ?: 'http') . '://' . $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '');
|
||||
$options['fopen']['request_fulluri'] = true;
|
||||
|
||||
if (isset($parsed_url['user']) && isset($parsed_url['pass'])) {
|
||||
$auth = base64_encode($parsed_url['user'] . ':' . $parsed_url['pass']);
|
||||
$options['fopen']['header'] = "Proxy-Authorization: Basic $auth";
|
||||
}
|
||||
}
|
||||
|
||||
if ($callback) {
|
||||
@@ -269,7 +277,18 @@ class Response
|
||||
// if proxy set add that
|
||||
$proxy_url = self::getGrav()['config']->get('system.proxy_url');
|
||||
if ($proxy_url) {
|
||||
$options['curl'][CURLOPT_PROXY] = $proxy_url;
|
||||
$parsed_url = parse_url($proxy_url);
|
||||
|
||||
$options['curl'][CURLOPT_PROXY] = $parsed_url['host'];
|
||||
$options['curl'][CURLOPT_PROXYTYPE] = 'HTTP';
|
||||
|
||||
if (isset($parsed_url['port'])) {
|
||||
$options['curl'][CURLOPT_PROXYPORT] = $parsed_url['port'];
|
||||
}
|
||||
|
||||
if (isset($parsed_url['user']) && isset($parsed_url['pass'])) {
|
||||
$options['curl'][CURLOPT_PROXYUSERPWD] = $parsed_url['user'] . ':' . $parsed_url['pass'];
|
||||
}
|
||||
}
|
||||
|
||||
// no open_basedir set, we can proceed normally
|
||||
@@ -278,7 +297,7 @@ class Response
|
||||
return curl_exec($ch);
|
||||
}
|
||||
|
||||
$max_redirects = isset($options['curl'][CURLOPT_MAXREDIRS]) ? $options['curl'][CURLOPT_MAXREDIRS] : 3;
|
||||
$max_redirects = isset($options['curl'][CURLOPT_MAXREDIRS]) ? $options['curl'][CURLOPT_MAXREDIRS] : 3;
|
||||
$options['curl'][CURLOPT_FOLLOWLOCATION] = false;
|
||||
|
||||
// open_basedir set but no redirects to follow, we can disable followlocation and proceed normally
|
||||
|
||||
Reference in New Issue
Block a user