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 Original file line number Diff line number Diff line change @@ -150,11 +150,14 @@ def parse_trace_id(trace_id: str) -> dict[str, str]:
150
150
return trace_values
151
151
152
152
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 :
156
155
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
158
161
159
162
for bmt in binary_media_types :
160
163
type_and_subtype = bmt .split (";" )[0 ].split ("/" )
@@ -164,10 +167,10 @@ def accept_header_matches_binary_media_types(accept: str | None, binary_media_ty
164
167
if _type == "*" :
165
168
continue
166
169
167
- if subtype == "*" and accept_type == _type :
170
+ if subtype == "*" and mime_type == _type :
168
171
return True
169
172
170
- if accept_type == _type and accept_subtype == subtype :
173
+ if mime_type == _type and mime_subtype == subtype :
171
174
return True
172
175
173
176
return False
Original file line number Diff line number Diff line change 32
32
from ..gateway_response import IntegrationFailureError , InternalServerError
33
33
from ..header_utils import build_multi_value_headers
34
34
from ..helpers import (
35
- accept_header_matches_binary_media_types ,
36
35
get_lambda_function_arn_from_invocation_uri ,
37
36
get_source_arn ,
37
+ mime_type_matches_binary_media_types ,
38
38
render_uri_with_stage_variables ,
39
39
validate_sub_dict_of_typed_dict ,
40
40
)
@@ -395,7 +395,7 @@ def invoke(self, context: RestApiInvocationContext) -> EndpointResponse:
395
395
396
396
# TODO: maybe centralize this flag inside the context, when we are also using it for other integration types
397
397
# 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 (
399
399
context .invocation_request ["headers" ].get ("Accept" ),
400
400
context .deployment .rest_api .rest_api .get ("binaryMediaTypes" , []),
401
401
)
You can’t perform that action at this time.
0 commit comments