summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-04-25 13:56:06 +0000
committerDries Buytaert <dries@buytaert.net>2009-04-25 13:56:06 +0000
commite9946015c7cd235e1bc44c6c7b2edabbdb186b2f (patch)
treeb982e8975842f8272cc4bfea96a601c91c507f36
parent453d7c566e980a4940267769800f8a02517404b1 (diff)
downloadbrdo-e9946015c7cd235e1bc44c6c7b2edabbdb186b2f.tar.gz
brdo-e9946015c7cd235e1bc44c6c7b2edabbdb186b2f.tar.bz2
- Patch #345591 by pwolanin, JacobSingh: drupal_http_request() should return the original status message and protocol.
-rw-r--r--includes/common.inc13
-rw-r--r--modules/simpletest/tests/common.test6
2 files changed, 16 insertions, 3 deletions
diff --git a/includes/common.inc b/includes/common.inc
index ec1673585..6742e8ebe 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -426,12 +426,16 @@ function drupal_access_denied() {
* - code
* An integer containing the response status code, or the error code if
* an error occurred.
+ * - protocol
+ * The response protocol (e.g. HTTP/1.1 or HTTP/1.0).
+ * - status_message
+ * The status message from the response, if a response was received.
* - redirect_code
* If redirected, an integer containing the initial response status code.
* - redirect_url
* If redirected, a string containing the redirection location.
* - error
- * If an error occurred, the error message.
+ * If an error occurred, the error message. Otherwise not set.
* - headers
* An array containing the response headers as name/value pairs.
* - data
@@ -550,7 +554,10 @@ 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) = explode(' ', trim(array_shift($response)), 3);
+ list($protocol, $code, $status_message) = explode(' ', trim(array_shift($response)), 3);
+ $result->protocol = $protocol;
+ $result->status_message = $status_message;
+
$result->headers = array();
// Parse the response headers.
@@ -632,7 +639,7 @@ function drupal_http_request($url, array $options = array()) {
$result->redirect_url = $location;
break;
default:
- $result->error = $status;
+ $result->error = $status_message;
}
return $result;
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 58b37cfc8..a04cf6e2b 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -303,6 +303,12 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
$this->assertEqual($result->code, 200, t('Fetched page successfully.'));
$this->drupalSetContent($result->data);
$this->assertTitle(variable_get('site_name', 'Drupal'), t('Site title matches.'));
+
+ // Test that code and status message is returned.
+ $result = drupal_http_request(url('pagedoesnotexist', array('absolute' => TRUE)));
+ $this->assertEqual($result->protocol, 'HTTP/1.0', t('Result protocol is set as HTTP/1.0'));
+ $this->assertEqual($result->code, '404', t('Result code is 404'));
+ $this->assertEqual($result->status_message, 'Not Found', t('Result status message is "Not Found"'));
}
function testDrupalHTTPRequestBasicAuth() {