/**
* @param ElasticaRequest $elasticaRequest
* @param Connection $connection
*
* @return HttpAdapterRequest
*/
protected function _createHttpAdapterRequest(ElasticaRequest $elasticaRequest, Connection $connection)
{
$data = $elasticaRequest->getData();
$body = null;
$method = $elasticaRequest->getMethod();
$headers = $connection->hasConfig('headers') ?: array();
if (!empty($data) || '0' === $data) {
if ($method == ElasticaRequest::GET) {
$method = ElasticaRequest::POST;
}
if ($this->hasParam('postWithRequestBody') && $this->getParam('postWithRequestBody') == true) {
$elasticaRequest->setMethod(ElasticaRequest::POST);
$method = ElasticaRequest::POST;
}
if (is_array($data)) {
$body = JSON::stringify($data, 'JSON_ELASTICSEARCH');
} else {
$body = $data;
}
}
$url = $this->_getUri($elasticaRequest, $connection);
$streamBody = new StringStream($body);
return new HttpAdapterRequest($url, $method, HttpAdapterRequest::PROTOCOL_VERSION_1_1, $headers, $streamBody);
}