You are here

protected function SearchApiSolrConnection::makeHttpRequest in Search API Solr 7

Sends an HTTP request to Solr.

This is just a wrapper around drupal_http_request().

Parameters

string $url: The URL to which the request should be sent.

array $options: Additional options for the request, as recognized by drupal_http_request().

Return value

object The HTTP response, as returned by drupal_http_request().

4 calls to SearchApiSolrConnection::makeHttpRequest()
SearchApiSolrConnection::makeServletRequest in includes/solr_connection.inc
Makes a request to a servlet (a path) that's not a standard path.
SearchApiSolrConnection::ping in includes/solr_connection.inc
Calls the /admin/ping servlet, to test the connection to the server.
SearchApiSolrConnection::sendRawGet in includes/solr_connection.inc
Sends a GET request to the Solr server.
SearchApiSolrConnection::sendRawPost in includes/solr_connection.inc
Sends a PUT request to the Solr server.

File

includes/solr_connection.inc, line 630

Class

SearchApiSolrConnection
Represents a Solr server resource.

Code

protected function makeHttpRequest($url, array $options = array()) {
  if (empty($options['method']) || $options['method'] == 'GET' || $options['method'] == 'HEAD') {

    // Make sure we are not sending a request body.
    $options['data'] = NULL;
  }
  if ($this->http_auth) {
    $options['headers']['Authorization'] = $this->http_auth;
  }
  if ($this->stream_context) {
    $options['context'] = $this->stream_context;
  }
  $result = drupal_http_request($url, $options);
  $result->status_message = isset($result->status_message) ? $result->status_message : '';
  if (!isset($result->code) || $result->code < 0) {
    $result->code = 0;
    $result->status_message = 'Request failed';
    $result->protocol = 'HTTP/1.0';
  }

  // Additional information may be in the error property.
  if (isset($result->error)) {
    $result->status_message .= ': ' . check_plain($result->error);
  }
  if (!isset($result->data)) {
    $result->data = '';
    $result->response = NULL;
  }
  else {
    $response = json_decode($result->data);
    if (is_object($response)) {
      foreach ($response as $key => $value) {
        $result->{$key} = $value;
      }
    }
  }
  return $result;
}