8000 fix OpenSearch proxy for GZIP encoded responses (#8628) · localstack/localstack@75ad307 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75ad307

Browse files
authored
fix OpenSearch proxy for GZIP encoded responses (#8628)
1 parent 28427b9 commit 75ad307

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

localstack/services/opensearch/cluster.py

Lines changed: 4 additions & 3 deletions
< 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
EngineType,
1515
ValidationException,
1616
)
17-
from localstack.http.client import SimpleRequestsClient
17+
from localstack.http.client import SimpleStreamingRequestsClient
1818
from localstack.http.proxy import ProxyHandler
1919
from localstack.services.edge import ROUTER
2020
from localstack.services.infra import DEFAULT_BACKEND_HOST
@@ -229,7 +229,7 @@ def register_cluster(
229229
forward_url = config.OPENSEARCH_CUSTOM_BACKEND or forward_url
230230

231231
# if the opensearch security plugin is enabled, only TLS connections are allowed, but the cert cannot be verified
232-
client = SimpleRequestsClient()
232+
client = SimpleStreamingRequestsClient()
233233
client.session.verify = False
234234
endpoint = ProxyHandler(forward_url, client)
235235

@@ -416,7 +416,8 @@ def _base_settings(self, dirs) -> CommandSettings:
416416
"http.publish_port": self.port,
417417
"transport.port": "0",
418418
"network.host": self.host,
419-
"http.compression": "false",
419+
# TODO this breaks the cluster check?!
420+
"http.compression": "true",
420421
"path.data": f'"{dirs.data}"',
421422
"path.repo": f'"{dirs.backup}"',
422423
"discovery.type": "single-node",

tests/integration/test_opensearch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import gzip
12
import json
23
import logging
34
import os
@@ -473,6 +474,13 @@ def test_describe_domains(self, opensearch_domain, aws_client):
473474
assert len(response["DomainStatusList"]) == 1
474475
assert response["DomainStatusList"][0]["DomainName"] == opensearch_domain
475476

477+
def test_gzip_responses(self, opensearch_endpoint):
478+
gzip_response = requests.get(opensearch_endpoint, stream=True)
479+
# get the raw data, don't let requests decode the response
480+
raw_data = b"".join(chunk for chunk in gzip_response.raw.stream(1024, decode_content=False))
481+
# force the gzip decoding here (which would raise an exception if it's not actually gzip)
482+
assert gzip.decompress(raw_data)
483+
476484
def test_domain_version(self, opensearch_domain, opensearch_create_domain, aws_client):
477485
response = aws_client.opensearch.describe_domain(DomainName=opensearch_domain)
478486
assert "DomainStatus" in response

0 commit comments

Comments
 (0)
0