diff --git a/includes/common.inc b/includes/common.inc index 40a7919..38aff66 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -990,7 +990,16 @@ function drupal_http_request($url, array $options = array()) { $response = preg_split("/\r\n|\n|\r/", $response); // Parse the response status line. - list($protocol, $code, $status_message) = explode(' ', trim(array_shift($response)), 3); + list($protocol, $code_status_message) = explode(' ', trim(array_shift($response)), 2); + + // Check if the status message exists. + if (strpos($code_status_message, ' ') === FALSE) { + $code = $code_status_message; + $status_message = ''; + } + else { + list($code, $status_message) = explode(' ', $code_status_message, 2); + } $result->protocol = $protocol; $result->status_message = $status_message; diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 44eecdc..b784b28 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1063,6 +1063,9 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase { $multiple_redirect_3 = drupal_http_request(url('system-test/multiple-redirects/3', array('absolute' => TRUE)), array('max_redirects' => 3)); $this->assertEqual($multiple_redirect_3->redirect_url, $multiple_redirect_final_url, 'redirect_url contains the final redirection location after 3 redirects.'); + + $no_reason = drupal_http_request(url('system-test/no-reason-phrase', array('absolute' => TRUE))); + $this->assertFalse($no_reason->status_message, 'Reason phrase is empty'); } /** diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module index 8cb0e83..af57193 100644 --- a/modules/simpletest/tests/system_test.module +++ b/modules/simpletest/tests/system_test.module @@ -106,6 +106,13 @@ function system_test_menu() { 'type' => MENU_CALLBACK, ); + $items['system-test/no-reason-phrase'] = array( + 'title' => 'Test response code without a reason', + 'page callback' => 'system_test_no_reason', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + return $items; } @@ -339,6 +346,14 @@ function system_test_page_shutdown_functions($arg1, $arg2) { } /** + * A page callback that omites the reason phrase. + */ +function system_test_no_reason() { + header('HTTP/1.1 999'); + exit; +} + +/** * Dummy shutdown function which registers another shutdown function. */ function _system_test_first_shutdown_function($arg1, $arg2) {