1 backdrop_web_test_case.php protected BackdropWebTestCase::curlHeaderCallback($curlHandler, $header)

Reads headers and registers errors received from the tested site.

Parameters

$curlHandler: The cURL handler.

$header: An header.

Return value

int: The header length in bytes.

See also

_backdrop_log_error().

File

core/modules/simpletest/backdrop_web_test_case.php, line 2090

Class

BackdropWebTestCase
Test case for typical Backdrop tests.

Code

protected function curlHeaderCallback($curlHandler, $header) {
  // Header fields can be extended over multiple lines by preceding each
  // extra line with at least one SP or HT. They should be joined on receive.
  // Details are in RFC2616 section 4.
  if ($header[0] == ' ' || $header[0] == "\t") {
    // Normalize whitespace between chucks.
    $this->headers[] = array_pop($this->headers) . ' ' . trim($header);
  }
  else {
    $this->headers[] = $header;
  }

  // Errors are being sent via X-Backdrop-Assertion-* headers,
  // generated by _backdrop_log_error() in the exact form required
  // by BackdropWebTestCase::error().
  if (preg_match('/^X-Backdrop-Assertion-[0-9]+: (.*)$/', trim($header), $matches)) {
    // Call BackdropWebTestCase::error() with the parameters from the header.
    call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1])));
  }

  // Save cookies.
  if (preg_match('/^Set-Cookie: ([^=]+)=(.+)/', $header, $matches)) {
    $name = $matches[1];
    $parts = array_map('trim', explode(';', $matches[2]));
    $value = array_shift($parts);
    $this->cookies[$name] = array('value' => $value, 'secure' => in_array('secure', $parts));
    if ($name == $this->session_name) {
      if ($value != 'deleted') {
        $this->session_id = $value;
      }
      else {
        $this->session_id = NULL;
      }
    }
  }

  // This is required by cURL.
  return strlen($header);
}