protected function BetterStatisticsTest::simpleCurlExec in Better Statistics 7
See also
1 call to BetterStatisticsTest::simpleCurlExec()
- BetterStatisticsTest::betterStatisticsPost in ./
better_statistics.test - Execute a POST request against a Drupal path with a JSON payload.
File
- ./
better_statistics.test, line 496 - Tests for the Better Statistics Module.
Class
- BetterStatisticsTest
- Functional tests for Better Statistics.
Code
protected function simpleCurlExec($curl_options, $redirect = FALSE) {
$this
->curlInitialize();
if (!empty($curl_options[CURLOPT_URL]) && strpos($curl_options[CURLOPT_URL], '#')) {
$original_url = $curl_options[CURLOPT_URL];
$curl_options[CURLOPT_URL] = strtok($curl_options[CURLOPT_URL], '#');
}
$url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
if (!empty($curl_options[CURLOPT_POST])) {
$curl_options[CURLOPT_HTTPHEADER][] = 'Expect:';
}
curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
if (!$redirect) {
// Reset headers, the session ID and the redirect counter.
$this->session_id = NULL;
$this->headers = array();
$this->redirect_count = 0;
}
$content = curl_exec($this->curlHandle);
$status = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
if (in_array($status, array(
300,
301,
302,
303,
305,
307,
)) && $this->redirect_count < variable_get('simpletest_maximum_redirects', 5)) {
if ($this
->drupalGetHeader('location')) {
$this->redirect_count++;
$curl_options = array();
$curl_options[CURLOPT_URL] = $this
->drupalGetHeader('location');
$curl_options[CURLOPT_HTTPGET] = TRUE;
return $this
->simpleCurlExec($curl_options, TRUE);
}
}
$this
->drupalSetContent($content, isset($original_url) ? $original_url : curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL));
}