Skip to content

Commit

Permalink
Moved the "accept-encoding" part to be always effective, the compress…
Browse files Browse the repository at this point in the history
…ion will depend of the ES configuration, we only say that we support it.
  • Loading branch information
yboucher committed Dec 12, 2015
1 parent 46fcb8c commit a1bed14
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/Elastica/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function exec(Request $request, array $params)
curl_setopt($conn, CURLOPT_TIMEOUT, $connection->getTimeout());
curl_setopt($conn, CURLOPT_FORBID_REUSE, 0);

// Tell ES that we support the compressed responses
// An "Accept-Encoding" header containing all supported encoding types is sent
// curl will decode the response automatically if the response is encoded
curl_setopt($conn, CURLOPT_ENCODING, '');

/* @see Connection::setConnectTimeout() */
$connectTimeout = $connection->getConnectTimeout();
if ($connectTimeout > 0) {
Expand Down Expand Up @@ -119,15 +124,11 @@ public function exec(Request $request, array $params)
$content = str_replace('\/', '/', $content);

if ($connection->hasCompression()) {
// An "Accept-Encoding" header containing all supported encoding types is sent
// Curl will decode the response automatically
curl_setopt($conn, CURLOPT_ENCODING, '');
// Compress the body of the request ...
curl_setopt($conn, CURLOPT_POSTFIELDS, gzencode($content));

// Let's precise that the request is also compressed
// ... and tell ES that it is compressed
curl_setopt($conn, CURLOPT_HTTPHEADER, array('Content-Encoding: gzip'));

// Let's compress the request body,
curl_setopt($conn, CURLOPT_POSTFIELDS, gzencode($content));
} else {
curl_setopt($conn, CURLOPT_POSTFIELDS, $content);
}
Expand Down

0 comments on commit a1bed14

Please sign in to comment.