- Patch #345591 by pwolanin, JacobSingh: drupal_http_request() should return the original status message and protocol.
parent
453d7c566e
commit
e9946015c7
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue