public function SearchSubscriber::preExecuteRequest in Acquia Connector 8
Build Acquia Search Solr Authenticator.
Parameters
\Drupal\search_api_solr\Solarium\EventDispatcher\EventProxy $event: PreExecuteRequest event.
File
- acquia_search/
src/ EventSubscriber/ SearchSubscriber.php, line 65
Class
- SearchSubscriber
- Extends Solarium plugin: authenticate, etc.
Namespace
Drupal\acquia_search\EventSubscriberCode
public function preExecuteRequest(EventProxy $event) {
// If no client exists, its not an acquia solr server.
if (!$this->client) {
return;
}
/** @var \Solarium\Core\Client\Request $request */
$request = $event
->getRequest();
$request
->addParam('request_id', uniqid(), TRUE);
// If we're hosted on Acquia, and have an Acquia request ID,
// append it to the request so that we map Solr queries to Acquia search
// requests.
if (isset($_ENV['HTTP_X_REQUEST_ID'])) {
$xid = empty($_ENV['HTTP_X_REQUEST_ID']) ? '-' : $_ENV['HTTP_X_REQUEST_ID'];
$request
->addParam('x-request-id', $xid);
}
$endpoint = $this->client
->getEndpoint();
$this->uri = AdapterHelper::buildUri($request, $endpoint);
$this->nonce = Crypt::randomBytesBase64(24);
$raw_post_data = $request
->getRawData();
// We don't have any raw POST data for pings only.
if (!$raw_post_data) {
$parsed_url = parse_url($this->uri);
$path = $parsed_url['path'] ?? '/';
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$raw_post_data = $path . $query;
}
$cookie = $this
->calculateAuthCookie($raw_post_data, $this->nonce, time());
$request
->addHeader('Cookie: ' . $cookie);
$request
->addHeader('User-Agent: ' . 'acquia_search/' . \Drupal::config('acquia_search.settings')
->get('version'));
}