You are here

protected function ServicesWebTestCase::curlExec in Services 6.3

Same name and namespace in other branches
  1. 7.3 tests/services.test \ServicesWebTestCase::curlExec()

Performs a cURL exec with the specified options after calling curlConnect().

Parameters

$curl_options: Custom cURL options.

Return value

Content returned from the exec.

Overrides DrupalWebTestCase::curlExec

4 calls to ServicesWebTestCase::curlExec()
ServicesWebTestCase::servicesDelete in tests/functional/ServicesWebTestCase.php
ServicesWebTestCase::servicesGet in tests/functional/ServicesWebTestCase.php
ServicesWebTestCase::servicesPost in tests/functional/ServicesWebTestCase.php
ServicesWebTestCase::servicesPut in tests/functional/ServicesWebTestCase.php

File

tests/functional/ServicesWebTestCase.php, line 395
Services base testing class.

Class

ServicesWebTestCase
@file Services base testing class.

Code

protected function curlExec($curl_options) {
  $this
    ->curlInitialize();
  $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
  if (!empty($curl_options[CURLOPT_POST])) {

    // This is a fix for the Curl library to prevent Expect: 100-continue
    // headers in POST requests, that may cause unexpected HTTP response
    // codes from some webservers (like lighttpd that returns a 417 error
    // code). It is done by setting an empty "Expect" header field that is
    // not overwritten by Curl.
    $curl_options[CURLOPT_HTTPHEADER][] = 'Expect:';
  }
  curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);

  // Reset headers and the session ID.
  $this->session_id = NULL;
  $this->headers = array();
  $this
    ->drupalSetContent(curl_exec($this->curlHandle), curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL));

  // Analyze the method for log message.
  $method = '';
  if (!empty($curl_options[CURLOPT_NOBODY])) {
    $method = 'HEAD';
  }
  if (empty($method) && !empty($curl_options[CURLOPT_PUT])) {
    $method = 'PUT';
  }
  if (empty($method) && !empty($curl_options[CURLOPT_CUSTOMREQUEST])) {
    $method = $curl_options[CURLOPT_CUSTOMREQUEST];
  }
  if (empty($method)) {
    $method = empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST';
  }
  $message_vars = array(
    '!method' => $method,
    '@url' => $url,
    '@status' => curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE),
    '!length' => format_size(drupal_strlen($this->content)),
  );
  $message = t('!method @url returned @status (!length).', $message_vars);
  $this
    ->assertTrue($this->content !== FALSE, $message, t('Browser'));
  return $this
    ->drupalGetContent();
}