Skip to content

Commit 294e374

Browse files
committed
port back mime_type helper changes
1 parent 79384b4 commit 294e374

File tree

2 files changed

+11
-8
lines changed
  • localstack-core/localstack/services/apigateway/next_gen/execute_api

2 files changed

+11
-8
lines changed

localstack-core/localstack/services/apigateway/next_gen/execute_api/helpers.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ def parse_trace_id(trace_id: str) -> dict[str, str]:
150150
return trace_values
151151

152152

153-
def accept_header_matches_binary_media_types(accept: str | None, binary_media_types: list[str]):
154-
accept_type_and_subtype = accept.split(",")[0].split(";")[0].split("/")
155-
if len(accept_type_and_subtype) != 2:
153+
def mime_type_matches_binary_media_types(mime_type: str | None, binary_media_types: list[str]):
154+
if not mime_type or not binary_media_types:
156155
return False
157-
accept_type, accept_subtype = accept_type_and_subtype
156+
157+
mime_type_and_subtype = mime_type.split(",")[0].split(";")[0].split("/")
158+
if len(mime_type_and_subtype) != 2:
159+
return False
160+
mime_type, mime_subtype = mime_type_and_subtype
158161

159162
for bmt in binary_media_types:
160163
type_and_subtype = bmt.split(";")[0].split("/")
@@ -164,10 +167,10 @@ def accept_header_matches_binary_media_types(accept: str | None, binary_media_ty
164167
if _type == "*":
165168
continue
166169

167-
if subtype == "*" and accept_type == _type:
170+
if subtype == "*" and mime_type == _type:
168171
return True
169172

170-
if accept_type == _type and accept_subtype == subtype:
173+
if mime_type == _type and mime_subtype == subtype:
171174
return True
172175

173176
return False

localstack-core/localstack/services/apigateway/next_gen/execute_api/integrations/aws.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
from ..gateway_response import IntegrationFailureError, InternalServerError
3333
from ..header_utils import build_multi_value_headers
3434
from ..helpers import (
35-
accept_header_matches_binary_media_types,
3635
get_lambda_function_arn_from_invocation_uri,
3736
get_source_arn,
37+
mime_type_matches_binary_media_types,
3838
render_uri_with_stage_variables,
3939
validate_sub_dict_of_typed_dict,
4040
)
@@ -395,7 +395,7 @@ def invoke(self, context: RestApiInvocationContext) -> EndpointResponse:
395395

396396
# TODO: maybe centralize this flag inside the context, when we are also using it for other integration types
397397
# AWS_PROXY behaves a bit differently, but this could checked only once earlier
398-
binary_response_accepted = accept_header_matches_binary_media_types(
398+
binary_response_accepted = mime_type_matches_binary_media_types(
399399
context.invocation_request["headers"].get("Accept"),
400400
context.deployment.rest_api.rest_api.get("binaryMediaTypes", []),
401401
)

0 commit comments

Comments
 (0)