Commit 534287b1 authored by Dries's avatar Dries

- Patch #245990 by pwolanin: further clean-up of the HTTP request status fail problem.

parent a10731ce
......@@ -459,23 +459,7 @@ function drupal_access_denied() {
function drupal_http_request($url, array $options = array()) {
global $db_prefix;
static $self_test = FALSE;
$result = new stdClass();
// Try to clear the drupal_http_request_fails variable if it's set. We
// can't tie this call to any error because there is no surefire way to
// tell whether a request has failed, so we add the check to places where
// some parsing has failed.
if (!$self_test && variable_get('drupal_http_request_fails', FALSE)) {
$self_test = TRUE;
$works = module_invoke('system', 'check_http_request');
$self_test = FALSE;
if (!$works) {
// Do not bother with further operations if we already know that we
// have no chance.
$result->error = t("The server can't issue HTTP requests");
return $result;
}
}
// Parse the URL and make sure we can handle the schema.
$uri = @parse_url($url);
......@@ -513,6 +497,13 @@ function drupal_http_request($url, array $options = array()) {
// clash with the HTTP status codes.
$result->code = -$errno;
$result->error = trim($errstr);
// Mark that this request failed. This will trigger a check of the web
// server's ability to make outgoing HTTP requests the next time that
// requirements checking is performed.
// @see system_requirements()
variable_set('drupal_http_request_fails', TRUE);
return $result;
}
......
......@@ -349,7 +349,6 @@ function xmlrpc_error($code = NULL, $message = NULL) {
$xmlrpc_error->is_error = TRUE;
$xmlrpc_error->code = $code;
$xmlrpc_error->message = $message;
module_invoke('system', 'check_http_request');
}
return $xmlrpc_error;
}
......
......@@ -76,6 +76,5 @@ function aggregator_aggregator_fetch($feed) {
default:
watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed->title, '%error' => $result->code . ' ' . $result->error), WATCHDOG_WARNING);
drupal_set_message(t('The feed from %site seems to be broken, because of error "%error".', array('%site' => $feed->title, '%error' => $result->code . ' ' . $result->error)));
module_invoke('system', 'check_http_request');
}
}
......@@ -316,9 +316,6 @@ function openid_discovery($claimed_id) {
}
}
}
if (!$services) {
module_invoke('system', 'check_http_request');
}
return $services;
}
......@@ -354,13 +351,11 @@ function openid_association($op_endpoint) {
);
$assoc_result = drupal_http_request($op_endpoint, $assoc_options);
if (isset($assoc_result->error)) {
module_invoke('system', 'check_http_request');
return FALSE;
}
$assoc_response = _openid_parse_message($assoc_result->data);
if (isset($assoc_response['mode']) && $assoc_response['mode'] == 'error') {
module_invoke('system', 'check_http_request');
return FALSE;
}
......@@ -529,8 +524,5 @@ function openid_verify_assertion($op_endpoint, $response) {
}
}
}
if (!$valid) {
module_invoke('system', 'check_http_request');
}
return $valid;
}
......@@ -256,8 +256,8 @@ function system_requirements($phase) {
include_once DRUPAL_ROOT . '/includes/unicode.inc';
$requirements = array_merge($requirements, unicode_requirements());
// Check for update status module.
if ($phase == 'runtime') {
// Check for update status module.
if (!module_exists('update')) {
$requirements['update status'] = array(
'value' => $t('Not enabled'),
......@@ -269,16 +269,18 @@ function system_requirements($phase) {
$requirements['update status'] = array(
'value' => $t('Enabled'),
);
if (variable_get('drupal_http_request_fails', FALSE)) {
$requirements['http requests'] = array(
'title' => $t('HTTP request status'),
'value' => $t('Fails'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services.'),
);
}
}
$requirements['update status']['title'] = $t('Update notifications');
// Check that Drupal can issue HTTP requests.
if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
$requirements['http requests'] = array(
'title' => $t('HTTP request status'),
'value' => $t('Fails'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services. If you are certain that Drupal can access web pages but you are still seeing this message, you may add <code>$conf[\'drupal_http_request_fails\'] = FALSE;</code> to the bottom of your settings.php file.'),
);
}
}
return $requirements;
......
......@@ -2177,12 +2177,14 @@ function system_time_zones($blank = NULL) {
* will contain an error.
*
* @return
* Whether the www.example.com page can be requested via HTTP.
* TRUE if this installation can issue HTTP requests.
*/
function system_check_http_request() {
$result = drupal_http_request('http://www.example.com');
// If the resulting page contains RFC 2606 then we got the page we wanted.
$works = isset($result->data) && preg_match('/RFC\s+2606/', $result->data);
// Try to get the content of the front page via drupal_http_request().
$result = drupal_http_request(url('', array('absolute' => TRUE)));
// We only care that we get a http response - this means that Drupal
// can make a http request.
$works = isset($result->code) && ($result->code >= 100) && ($result->code < 600);
variable_set('drupal_http_request_fails', !$works);
return $works;
}
......
......@@ -56,7 +56,6 @@ function _update_refresh() {
watchdog('update', 'Fetched information about all available new releases and updates.', array(), WATCHDOG_NOTICE, l(t('view'), 'admin/reports/updates'));
}
else {
module_invoke('system', 'check_http_request');
watchdog('update', 'Unable to fetch any information about available new releases and updates.', array(), WATCHDOG_ERROR, l(t('view'), 'admin/reports/updates'));
}
return $available;
......
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