1 common.inc _backdrop_parse_response_status($response)

Split an HTTP response status line into components.

Refactored out of backdrop_http_request() so it can be unit tested.

Status line definition


string $response: The response status line, e.g. 'HTTP/1.1 500 Internal Server Error'

Return value

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'

Related topics


core/includes/common.inc, line 1347
Common functions that many Backdrop modules will need to reference.


function _backdrop_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;