#245990 From: <> --- includes/common.inc | 24 ++++++----------- includes/xmlrpc.inc | 1 - modules/aggregator/aggregator.fetcher.inc | 1 - modules/openid/openid.module | 8 ------ modules/system/system.install | 19 ++++++++----- modules/system/system.module | 42 +++++++++++++++++++++++++---- modules/update/update.fetch.inc | 1 - 7 files changed, 56 insertions(+), 40 deletions(-) diff --git includes/common.inc includes/common.inc index b7e4042..6a4e2c5 100644 --- includes/common.inc +++ includes/common.inc @@ -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,9 +497,17 @@ 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 be cleared by the next request, + // or manually by the site administrator from the report screen. + variable_set('drupal_http_request_fails', TRUE); + return $result; } + // This request worked, clear the flag. + variable_set('drupal_http_request_fails', FALSE); + // Construct the path to act on. $path = isset($uri['path']) ? $uri['path'] : '/'; if (isset($uri['query'])) { diff --git includes/xmlrpc.inc includes/xmlrpc.inc index 551ef68..c49575a 100644 --- includes/xmlrpc.inc +++ includes/xmlrpc.inc @@ -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; } diff --git modules/aggregator/aggregator.fetcher.inc modules/aggregator/aggregator.fetcher.inc index cdd155d..88e4315 100644 --- modules/aggregator/aggregator.fetcher.inc +++ modules/aggregator/aggregator.fetcher.inc @@ -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'); } } diff --git modules/openid/openid.module modules/openid/openid.module index 9cfe383..a385d5d 100644 --- modules/openid/openid.module +++ modules/openid/openid.module @@ -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; } diff --git modules/system/system.install modules/system/system.install index 719af8f..6ef57e6 100644 --- modules/system/system.install +++ modules/system/system.install @@ -269,14 +269,19 @@ 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.'), - ); + } + + if (variable_get('drupal_http_request_fails', FALSE)) { + $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 (!variable_get('drupal_bypass_http_request', FALSE)) { + $description .= '
' . $t("If clicking the test again link above doesn't clear this message, and you are certain that your server can access web pages, please add \$conf['drupal_bypass_http_request'] = TRUE to the bottom of your settings.php file."); } + $requirements['http requests'] = array( + 'title' => $t('HTTP request status'), + 'value' => $t('Fails (!link)', array('!link' => l(variable_get('drupal_bypass_http_request', FALSE) ? $t('clear this') : $t('test again'), 'admin/reports/request-test'))), + 'severity' => REQUIREMENT_ERROR, + 'description' => $description, + ); } $requirements['update status']['title'] = $t('Update notifications'); } diff --git modules/system/system.module modules/system/system.module index 10a8880..04d55d4 100644 --- modules/system/system.module +++ modules/system/system.module @@ -661,6 +661,21 @@ function system_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); + $items['admin/reports/request-test'] = array( + 'title' => 'Request test', + 'page callback' => 'system_check_http_request_page', + 'access arguments' => array('access site reports'), + 'type' => MENU_CALLBACK, + ); + // Menu handler to test that drupal_http_request() works locally. + // @see system_check_http_request() + $items['admin/reports/request-test/data'] = array( + 'title' => 'Request test', + 'page callback' => 'drupal_json', + 'page arguments' => array('request test'), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); // Reports: $items['admin/reports'] = array( @@ -2148,6 +2163,14 @@ function system_time_zones($blank = NULL) { } /** + * Menu callback; try to clear the drupal_http_request_fails(). + */ +function system_check_http_request_page() { + system_check_http_request(); + drupal_goto('admin/reports/status'); +} + +/** * Checks whether the server is capable of issuing HTTP requests. * * The function sets the drupal_http_request_fail system variable to TRUE if @@ -2155,14 +2178,21 @@ 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); - variable_set('drupal_http_request_fails', !$works); - return $works; + if (variable_get('drupal_bypass_http_request', FALSE)) { + variable_set('drupal_http_request_fails', FALSE); + return FALSE; + } + else { + // Check whether we can do any request at all. Try to get the content of a + // test page via drupal_http_request() . + $result = drupal_http_request(url('admin/reports/request-test/data', array('absolute' => TRUE))); + $works = isset($result->data) && $result->data == '"request test"'; + variable_set('drupal_http_request_fails', !$works); + return $works; + } } /** diff --git modules/update/update.fetch.inc modules/update/update.fetch.inc index 1c901a2..49a5b22 100644 --- modules/update/update.fetch.inc +++ modules/update/update.fetch.inc @@ -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;