You are here

protected function RestWSBasicAuthTestCase::httpRequest in RESTful Web Services 7

Same name and namespace in other branches
  1. 7.2 restws_basic_auth/restws_basic_auth.test \RestWSBasicAuthTestCase::httpRequest()

Helper function to issue a HTTP request with simpletest's cURL.

Laregely copied from RestWSTestCase::httpRequest() and adpoted for Basic Auth.

1 call to RestWSBasicAuthTestCase::httpRequest()
RestWSBasicAuthTestCase::testCachePoisoning in restws_basic_auth/restws_basic_auth.test
Tests that an authenticated user response never gets into the page cache.

File

restws_basic_auth/restws_basic_auth.test, line 81
RESTWS Basic Auth tests.

Class

RestWSBasicAuthTestCase
@file RESTWS Basic Auth tests.

Code

protected function httpRequest($url, $account = NULL) {

  // Always reset the cURL options so that no options from previous requests
  // are set.
  unset($this->curlHandle);
  $method = 'GET';
  $curl_options = array(
    CURLOPT_HTTPGET => TRUE,
    CURLOPT_URL => url($url, array(
      'absolute' => TRUE,
    )),
    CURLOPT_NOBODY => FALSE,
  );
  if (isset($account)) {
    $curl_options[CURLOPT_USERPWD] = $account->name . ':' . $account->pass_raw;
  }
  $response = $this
    ->curlExec($curl_options);
  $headers = $this
    ->drupalGetHeaders();
  $headers = print_r($headers, TRUE);
  $this
    ->verbose($method . ' request to: ' . $url . '<hr />Code: ' . curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE) . '<hr />Response headers: ' . $headers . '<hr />Response body: ' . $response);
  return $response;
}