17
17
Dict ,
18
18
Generic ,
19
19
List ,
20
+ Mapping ,
20
21
Match ,
21
22
Optional ,
22
23
Pattern ,
@@ -200,7 +201,7 @@ def to_dict(self, origin: Optional[str]) -> Dict[str, str]:
200
201
return {}
201
202
202
203
# The origin matched an allowed origin, so return the CORS headers
203
- headers : Dict [ str , str ] = {
204
+ headers = {
204
205
"Access-Control-Allow-Origin" : origin ,
205
206
"Access-Control-Allow-Headers" : "," .join (sorted (self .allow_headers )),
206
207
}
@@ -222,7 +223,7 @@ def __init__(
222
223
status_code : int ,
223
224
content_type : Optional [str ] = None ,
224
225
body : Optional [ResponseT ] = None ,
225
- headers : Optional [Dict [str , Union [str , List [str ]]]] = None ,
226
+ headers : Optional [Mapping [str , Union [str , List [str ]]]] = None ,
226
227
cookies : Optional [List [Cookie ]] = None ,
227
228
compress : Optional [bool ] = None ,
228
229
):
@@ -237,15 +238,15 @@ def __init__(
237
238
provided http headers
238
239
body: Union[str, bytes, None]
239
240
Optionally set the response body. Note: bytes body will be automatically base64 encoded
240
- headers: dict [str, Union[str, List[str]]]
241
+ headers: Mapping [str, Union[str, List[str]]]
241
242
Optionally set specific http headers. Setting "Content-Type" here would override the `content_type` value.
242
243
cookies: list[Cookie]
243
244
Optionally set cookies.
244
245
"""
245
246
self .status_code = status_code
246
247
self .body = body
247
248
self .base64_encoded = False
248
- self .headers : Dict [str , Union [str , List [str ]]] = headers if headers else {}
249
+ self .headers : Dict [str , Union [str , List [str ]]] = dict ( headers ) if headers else {}
249
250
self .cookies = cookies or []
250
251
self .compress = compress
251
252
self .content_type = content_type
@@ -1940,7 +1941,7 @@ def _path_starts_with(path: str, prefix: str):
1940
1941
1941
1942
def _not_found (self , method : str ) -> ResponseBuilder :
1942
1943
"""Called when no matching route was found and includes support for the cors preflight response"""
1943
- headers : Dict [ str , Union [ str , List [ str ]]] = {}
1944
+ headers = {}
1944
1945
if self ._cors :
1945
1946
logger .debug ("CORS is enabled, updating headers." )
1946
1947
headers .update (self ._cors .to_dict (self .current_event .get_header_value ("Origin" )))
0 commit comments