Skip to content

Elastic cloud Client prevents decompression of gzip compressed responses #1241

@laurenzonneveld

Description

@laurenzonneveld

Summary of problem or feature request

ClientBuilder::build() adds an Accept-Encoding:gzip header when elasticCloudId is provided but does not handle decompression of gzip compressed responses.

We're using Symfony\Component\HttpClient\HttplugClient as asyncHttpClient which adds gzip by default but does not handle decoding when the Accept-Encoding header is explicitly set.

As per Symfony HTTPClient maintainer:

you explicitly send the request with the "accept-encoding" header. When you do this, you disable transparent compression and you opt-in for explicit compression, which means it's now your job to effectively decompress.
Don't send the header if that's not what you want.

symfony/symfony#34238 (comment)

Thus the Elastic Client should either handle decompressen (and check whether the required zlib PHP extension is loaded) or the Elastic Client should leave responsibility for decompression to the Psr\Http\Client\ClientInterface implementation and not set the header at all, we prefer the latter.

Code snippet of problem

if (!empty($this->cloudId)) {
    $transport->setHeader('Accept-Encoding', 'gzip');
}

And in Symfony HTTPClient:

$this->inflate = !isset($options['normalized_headers']['accept-encoding']); // This prevents decompression

System details

  • PHP version: 8.1.8
  • ES-PHP client version: 8.3.2
  • Elasticsearch version: 7.15.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions