You are here

function cf_http_headers_errors in Common Functionality 7.2

Same name and namespace in other branches
  1. 7 modules/cf_http/cf_http.module \cf_http_headers_errors()

Search through an array of http errors for common 400 and 500 http codes.

@see: cf_http_get_webpage()

Parameters

array $headers: An array of http headers.

Return value

array An array with the following structure:

  • error_code: number representing the error code of the error found,

0 otherwise.

  • key: array key of the header with the error.
  • value: error information associated with the error code.

Related topics

1 call to cf_http_headers_errors()
cf_http_parse_response in modules/cf_http/cf_http.module
Accepts and processes provided http content.

File

modules/cf_http/cf_http.module, line 172
Common Functionality - HTTP module.

Code

function cf_http_headers_errors(array &$headers) {
  foreach ($headers as $key => &$value) {
    $matches = array();
    if (preg_match('/^([45]\\d\\d)\\s/i', $value, $matches) > 0) {
      return array(
        'error_code' => $matches[1],
        'key' => $key,
        'value' => &$value,
      );
    }
  }
  return array(
    'error_code' => 0,
    'key' => '',
    'value' => '',
  );
}