diff options
author | David Rothstein <drothstein@gmail.com> | 2014-11-01 20:11:37 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2014-11-01 20:11:37 -0400 |
commit | 6b47cbf7d0aa4b0ad3b249a3e16d023fac0b140a (patch) | |
tree | b5c5d3498859a0c540e2943665d7bc504ae4de69 /includes | |
parent | 0e3d0beddbdd170165666af4451c088a0eb330d2 (diff) | |
download | brdo-6b47cbf7d0aa4b0ad3b249a3e16d023fac0b140a.tar.gz brdo-6b47cbf7d0aa4b0ad3b249a3e16d023fac0b140a.tar.bz2 |
Issue #205969 by Mile23, oadaeh, twistor, ssm2017 Binder, barraponto, superspring: Fixed drupal_http_request() assumes presence of Reason-Phrase in response Status-Line.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/includes/common.inc b/includes/common.inc index 84c5bfa89..a38d13b47 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -985,9 +985,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_message) = explode(' ', trim(array_shift($response)), 3); - $result->protocol = $protocol; - $result->status_message = $status_message; + $response_status_array = _drupal_parse_response_status(trim(array_shift($response))); + $result->protocol = $response_status_array['http_version']; + $result->status_message = $response_status_array['reason_phrase']; + $code = $response_status_array['response_code']; $result->headers = array(); @@ -1078,13 +1079,44 @@ function drupal_http_request($url, array $options = array()) { } break; default: - $result->error = $status_message; + $result->error = $result->status_message; } return $result; } /** + * Splits an HTTP response status line into components. + * + * See the @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html status line definition @endlink + * in RFC 2616. + * + * @param string $respone + * The response status line, for example 'HTTP/1.1 500 Internal Server Error'. + * + * @return array + * Keyed array containing the component parts. If the response is malformed, + * all possible parts will be extracted. 'reason_phrase' could be empty. + * Possible keys: + * - 'http_version' + * - 'response_code' + * - 'reason_phrase' + */ +function _drupal_parse_response_status($response) { + $response_array = explode(' ', trim($response), 3); + // Set up empty values. + $result = array( + 'reason_phrase' => '', + ); + $result['http_version'] = $response_array[0]; + $result['response_code'] = $response_array[1]; + if (isset($response_array[2])) { + $result['reason_phrase'] = $response_array[2]; + } + return $result; +} + +/** * Helper function for determining hosts excluded from needing a proxy. * * @return |