Commit 1ba261aa authored by mikeytown2's avatar mikeytown2

Issue #2205871 by mikeytown2: use a hostname function.

parent 333ba228
......@@ -319,20 +319,7 @@ function _httprl_build_drupal_root($level = 0, $hostname_mode = 0) {
// Use static for gethostbyname lookup.
static $dns_cache;
if (!empty($_SERVER['HTTP_HOST'])) {
$hostname = $_SERVER['HTTP_HOST'];
// If HTTP_HOST contains the port, use SERVER_NAME.
if (strpos($_SERVER['HTTP_HOST'], ':') !== FALSE) {
$hostname = $_SERVER['SERVER_NAME'];
}
}
elseif (!empty($_SERVER['SERVER_NAME'])) {
$hostname = $_SERVER['SERVER_NAME'];
}
else {
$hostname = '';
}
$hostname = httprl_get_hostname();
// Get Host.
$ip = httprl_variable_get('httprl_server_addr', FALSE);
if ($ip == -1 || $hostname_mode == 1) {
......@@ -1874,19 +1861,7 @@ function httprl_parse_data(&$result) {
// If location isn't fully qualified URL (as per W3 RFC2616), build one.
if (empty($location['scheme']) || empty($location['host'])) {
if (!empty($_SERVER['HTTP_HOST'])) {
$hostname = $_SERVER['HTTP_HOST'];
// If HTTP_HOST contains the port, use SERVER_NAME.
if (strpos($_SERVER['HTTP_HOST'], ':') !== FALSE) {
$hostname = $_SERVER['SERVER_NAME'];
}
}
elseif (!empty($_SERVER['SERVER_NAME'])) {
$hostname = $_SERVER['SERVER_NAME'];
}
else {
$hostname = '';
}
$hostname = httprl_get_hostname();
// Get the important parts from the original request.
$original_location = @parse_url($result->url);
......@@ -2303,20 +2278,7 @@ function httprl_queue_background_callback(&$args, &$result = NULL) {
// Set Host header.
if (empty($options['headers']['Host'])) {
if (!empty($_SERVER['HTTP_HOST'])) {
$hostname = $_SERVER['HTTP_HOST'];
// If HTTP_HOST contains the port, use SERVER_NAME.
if (strpos($_SERVER['HTTP_HOST'], ':') !== FALSE) {
$hostname = $_SERVER['SERVER_NAME'];
}
}
elseif (!empty($_SERVER['SERVER_NAME'])) {
$hostname = $_SERVER['SERVER_NAME'];
}
else {
$hostname = '';
}
$hostname = httprl_get_hostname();
if (!empty($hostname)) {
$options['headers']['Host'] = $hostname;
}
......@@ -3626,3 +3588,23 @@ function httprl_call_user_func_array_cache($callback, array $param_arr = array()
}
return isset($cache->data) ? $cache->data : NULL;
}
/**
* Get hostname of this server.
* @return string
* hostname or empty string; does not contain the port number.
*/
function httprl_get_hostname() {
if (!empty($_SERVER['HTTP_HOST'])) {
// If HTTP_HOST contains the port, use SERVER_NAME.
if (strpos($_SERVER['HTTP_HOST'], ':') !== FALSE) {
return $_SERVER['SERVER_NAME'];
}
return $_SERVER['HTTP_HOST'];
}
elseif (!empty($_SERVER['SERVER_NAME'])) {
return $_SERVER['SERVER_NAME'];
}
return '';
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment