Skip to content

Conversation

alexrashed
Copy link
Member

@alexrashed alexrashed commented Aug 30, 2023

Motivation

This PR addresses #8793, which describes an issue with the handling of the Accept-Encoding header when communicating with OpenSearch clusters with enabled http compression (as enabled statically with #8628).
This bug is actually caused by our HTTP client used in the Proxy infrastructure used to proxy requests from the client via LocalStack to the started OpenSearch server. This HTTP client always adds Accept-Encoding: gzip, deflate to the proxied HTTP request if no Accept-Encoding is set in the originating request.

With enabling the compression support for OpenSearch (i.e. OpenSearch will compress the responses using GZIP Content-Encoding in responses if the client sends gzip in the Accept-Encoding request header), this issue surfaced since every request to OpenSearch via LocalStack (which is the default) without the Accept-Encoding header (which is the default f.e. for a plain curl request).

It turns out that sending HTTP requests without any Accept-Encoding header is not possible with requests because it uses urllib3 under the hood, which in turn uses Python's http.client standard lib:

This means it's not really possible to identically relay a request which does not contain the Accept-Encoding header at all.

Changes

  • This PR explicitly sets the Accept-Encoding header to identity in case it's not set or None.
    • An alternative would have been just to circumvent the behavior of urllib3 by setting the Accept-Encoding header to None, but I wanted to make this behavior as explicit as possible (because it was quite a pain to get to the root of this weird behavior).
  • This PR also merges the SimpleHttpClient with the SimpleStreamingHttpClient. The latter was introduced with fix auto decoding of gzip for s3 vhost proxied requests #8148 in addition to the SimpleHttpClient where it should actually just have been an extension of the default (but that was understandable at the time in order to prevent too wide-ranging changes).
    • This is why I classified this change as "minor".

Testing

Testing this in Python is actually quite hard (since the test explicitly has to send a request without any Accept-Encoding header whatsoever). I actually had to directly use the HTTPConnection class of Python's std lib.

Fixes #8793.

@alexrashed alexrashed added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Aug 30, 2023
@alexrashed alexrashed added this to the 2.3 milestone Aug 30, 2023
@alexrashed alexrashed self-assigned this Aug 30, 2023
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find! LGTM! and thanks for cleaning up 🧹

@alexrashed alexrashed force-pushed the fix-opensearch-gzip-accept branch from 5e63b96 to f249ebd Compare August 30, 2023 13:35
@coveralls
Copy link

Coverage Status

coverage: 80.355% (-0.1%) from 80.457% when pulling 33caa24 on fix-opensearch-gzip-accept into 464880d on master.

@github-actions
Copy link

LocalStack Community integration with Pro

       2 files         2 suites   1h 22m 57s ⏱️
2 150 tests 1 676 ✔️ 474 💤 0
2 151 runs  1 676 ✔️ 475 💤 0

Results for commit 33caa24.

@alexrashed alexrashed merged commit f872187 into master Aug 30, 2023
@alexrashed alexrashed deleted the fix-opensearch-gzip-accept branch August 30, 2023 15:51
ashish1500616 pushed a commit to ashish1500616/localstack that referenced this pull request Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: OpenSearch response with compressed content
3 participants