Skip to content

Commit 4034ff4

Browse files
committed
drop Transfer-Encoding header from proxies response
1 parent 5ff3c27 commit 4034ff4

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

aws-replicator/aws_replicator/client/auth_proxy.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from botocore.model import OperationModel
1717
from localstack import config
1818
from localstack import config as localstack_config
19-
from localstack.aws.api import HttpRequest
2019
from localstack.aws.chain import HandlerChain
2120
from localstack.aws.chain import RequestContext as AwsRequestContext
2221
from localstack.aws.gateway import Gateway
@@ -45,8 +44,6 @@
4544
from aws_replicator.config import HANDLER_PATH_PROXIES
4645
from aws_replicator.shared.models import AddProxyRequest, ProxyConfig
4746

48-
from .http2_server import run_server
49-
5047
LOG = logging.getLogger(__name__)
5148
LOG.setLevel(logging.INFO)
5249
if config.DEBUG:
@@ -218,7 +215,7 @@ def _adjust_request_dict(self, service_name: str, request_dict: Dict):
218215
req_json["QueueOwnerAWSAccountId"] = account_id
219216
request_dict["body"] = to_bytes(json.dumps(req_json))
220217

221-
def _fix_headers(self, request: HttpRequest, service_name: str):
218+
def _fix_headers(self, request: Request, service_name: str):
222219
if service_name == "s3":
223220
# fix the Host header, to avoid bucket addressing issues
224221
host = request.headers.get("Host") or ""
@@ -543,8 +540,7 @@ def start_aws_auth_proxy_in_container(
543540
command = [
544541
"bash",
545542
"-c",
546-
# TODO: manually installing quart/h11/hypercorn as a dirty quick fix for now. To be fixed!
547-
f"{venv_activate}; pip install h11 hypercorn quart; pip install --upgrade --no-deps '{CLI_PIP_PACKAGE}'",
543+
f"{venv_activate}; pip install --upgrade --no-deps '{CLI_PIP_PACKAGE}'",
548544
]
549545
DOCKER_CLIENT.exec_in_container(container_name, command=command)
550546

aws-replicator/aws_replicator/server/aws_request_forwarder.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
4343
if response_ is None:
4444
return
4545

46-
response.update_from(response_)
47-
chain.stop()
46+
# Remove `Transfer-Encoding` header (which could be set to 'chunked'), to prevent client timeouts
47+
response_.headers.pop("Transfer-Encoding", None)
4848

4949
# set response details, then stop handler chain to return response
50-
# chain.response.data = response.raw_content
51-
# chain.response.status_code = response.status_code
52-
# chain.response.headers.update(dict(response.headers))
53-
# chain.stop()
54-
# chain.respond(response.status_code, response.raw_content, dict(response.headers))
50+
response.update_from(response_)
51+
chain.stop()
5552

5653
def select_proxy(self, context: RequestContext) -> Optional[ProxyInstance]:
5754
"""select a proxy responsible to forward a request to real AWS"""
@@ -141,7 +138,7 @@ def forward_request(self, context: RequestContext, proxy: ProxyInstance) -> requ
141138
response.headers,
142139
response.data,
143140
)
144-
except Exception as e:
141+
except Exception:
145142
LOG.exception("Exception while forwarding request")
146143
raise
147144

@@ -177,7 +174,7 @@ def forward_request(self, context: RequestContext, proxy: ProxyInstance) -> requ
177174
dict(result.headers),
178175
truncate(result.raw_content, max_length=500),
179176
)
180-
except requests.exceptions.ConnectionError as e:
177+
except requests.exceptions.ConnectionError:
181178
# remove unreachable proxy
182179
LOG.exception("Removing unreachable AWS forward proxy due to connection issue: %s", url)
183180
self.PROXY_INSTANCES.pop(port, None)

0 commit comments

Comments
 (0)