Modify $url and $options before making the HTTP request.
Paramètres
string $url: Full URL.
array $options: Options array for drupal_http_request().
bool $mod_url: Set to TRUE to try and modify the $url variable.
2 calls to advagg_install_url_mod()
- advagg_install_check_via_http dans ./
advagg.install - Make sure http requests to css/js files work correctly.
- advagg_install_chk_urls dans ./
advagg.install - Make sure http requests to css/js files work correctly.
Fichier
-
./
advagg.install, line 2552
Code
function advagg_install_url_mod(&$url, array &$options, $mod_url = FALSE) {
// Set the $options array.
// Set all timeouts to 8 seconds.
$options += array(
'timeout' => 8,
'dns_timeout' => 8,
'connect_timeout' => 8,
'ttfb_timeout' => 8,
);
// Set connection to closed to prevent keep-alive from causing a timeout.
$options['headers']['Connection'] = 'close';
// Set referrer to current page.
$options['headers']['Referer'] = $GLOBALS['base_root'] . request_uri();
$parts = @parse_url($url);
if (!is_array($parts)) {
return;
}
// Check if this is a protocol relative url, if so add a artificial scheme so
// that advagg_glue_url() will produce a proper absolute url. That will work
// with drupal_http_request().
if (!isset($parts['scheme']) && substr($url, 0, 2) == '//') {
global $base_url;
$parts['scheme'] = @parse_url($base_url, PHP_URL_SCHEME);
}
// Pass along user/pass in the URL.
$advagg_auth_basic_user = variable_get('advagg_auth_basic_user', ADVAGG_AUTH_BASIC_USER);
if (module_exists('shield')) {
$parts['user'] = variable_get('shield_user', '');
$parts['pass'] = variable_get('shield_pass', '');
}
elseif (isset($_SERVER['AUTH_TYPE']) && $_SERVER['AUTH_TYPE'] == 'Basic') {
$parts['user'] = $_SERVER['PHP_AUTH_USER'];
$parts['pass'] = $_SERVER['PHP_AUTH_PW'];
}
elseif (isset($_SERVER['HTTP_AUTHORIZATION']) && strpos($_SERVER['HTTP_AUTHORIZATION'], 'Basic ') === 0) {
$user_pass = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 5)));
$parts['user'] = $user_pass[0];
$parts['pass'] = $user_pass[1];
}
elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && strpos($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 'Basic ') === 0) {
$user_pass = explode(':', base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 5)));
$parts['user'] = $user_pass[0];
$parts['pass'] = $user_pass[1];
}
elseif (!empty($advagg_auth_basic_user)) {
$parts['user'] = $advagg_auth_basic_user;
$parts['pass'] = variable_get('advagg_auth_basic_pass', ADVAGG_AUTH_BASIC_PASS);
}
if ($mod_url) {
if (function_exists('httprl_build_url_self')) {
// Remove the base_path from path.
$path = substr($parts['path'], strlen($GLOBALS['base_path']));
$new_url = httprl_build_url_self($path);
}
else {
if (!empty($_SERVER['HTTP_HOST'])) {
if ($parts['host'] != $_SERVER['HTTP_HOST']) {
$parts['host'] = $_SERVER['HTTP_HOST'];
}
}
elseif (!empty($_SERVER['SERVER_NAME'])) {
if ($parts['host'] != $_SERVER['SERVER_NAME']) {
$parts['host'] = $_SERVER['SERVER_NAME'];
}
}
elseif (!empty($_SERVER['SERVER_ADDR'])) {
if ($parts['host'] != $_SERVER['SERVER_ADDR']) {
$parts['host'] = $_SERVER['SERVER_ADDR'];
}
}
else {
$parts['host'] = '127.0.0.1';
}
}
}
if (empty($new_url)) {
$new_url = advagg_glue_url($parts);
}
$url = $new_url;
}