27
27
28
28
@dataclass (frozen = True )
29
29
class CORSSettings :
30
- allow_headers : FrozenSet [str ]
31
- allow_methods : FrozenSet [str ]
32
- allow_origins : Tuple [re .Pattern , ...]
30
+ allow_headers : frozenset [str ]
31
+ allow_methods : frozenset [str ]
32
+ allow_origins : tuple [re .Pattern , ...]
33
33
always_send : bool
34
34
automatic_options : bool
35
- expose_headers : FrozenSet [str ]
35
+ expose_headers : frozenset [str ]
36
36
max_age : str
37
37
send_wildcard : bool
38
38
supports_credentials : bool
@@ -86,9 +86,9 @@ async def _assign_cors_settings(app, _):
86
86
def cors (
87
87
* ,
88
88
origin : Union [str , Default ] = _default ,
89
- expose_headers : Union [List [str ], Default ] = _default ,
90
- allow_headers : Union [List [str ], Default ] = _default ,
91
- allow_methods : Union [List [str ], Default ] = _default ,
89
+ expose_headers : Union [list [str ], Default ] = _default ,
90
+ allow_headers : Union [list [str ], Default ] = _default ,
91
+ allow_methods : Union [list [str ], Default ] = _default ,
92
92
supports_credentials : Union [bool , Default ] = _default ,
93
93
max_age : Union [str , int , timedelta , Default ] = _default ,
94
94
):
@@ -227,10 +227,10 @@ def _add_credentials_header(request: Request, response: HTTPResponse) -> None:
227
227
228
228
def _add_allow_header (request : Request , response : HTTPResponse ) -> None :
229
229
with_credentials = _is_request_with_credentials (request )
230
- request_headers = set (
230
+ request_headers = {
231
231
h .strip ().lower ()
232
232
for h in request .headers .get (REQUEST_HEADERS_HEADER , "" ).split ("," )
233
- )
233
+ }
234
234
allow_headers = _get_from_cors_ctx (
235
235
request , "_cors_allow_headers" , request .app .ctx .cors .allow_headers
236
236
)
@@ -297,16 +297,16 @@ def _add_vary_header(request: Request, response: HTTPResponse) -> None:
297
297
response .headers [VARY_HEADER ] = "origin"
298
298
299
299
300
- def _get_allow_origins (app : Sanic ) -> Tuple [re .Pattern , ...]:
300
+ def _get_allow_origins (app : Sanic ) -> tuple [re .Pattern , ...]:
301
301
origins = app .config .CORS_ORIGINS
302
302
return _parse_allow_origins (origins )
303
303
304
304
305
305
def _parse_allow_origins (
306
- value : Union [str , re .Pattern , List [Union [str , re .Pattern ]]],
307
- ) -> Tuple [re .Pattern , ...]:
306
+ value : Union [str , re .Pattern , list [Union [str , re .Pattern ]]],
307
+ ) -> tuple [re .Pattern , ...]:
308
308
origins : Optional [
309
- Union [List [str ], List [re .Pattern ], List [Union [str , re .Pattern ]]]
309
+ Union [list [str ], list [re .Pattern ], list [Union [str , re .Pattern ]]]
310
310
] = None
311
311
if value and isinstance (value , str ):
312
312
if value == "*" :
@@ -326,7 +326,7 @@ def _parse_allow_origins(
326
326
)
327
327
328
328
329
- def _get_expose_headers (app : Sanic ) -> FrozenSet [str ]:
329
+ def _get_expose_headers (app : Sanic ) -> frozenset [str ]:
330
330
expose_headers = (
331
331
(
332
332
app .config .CORS_EXPOSE_HEADERS
@@ -341,11 +341,11 @@ def _get_expose_headers(app: Sanic) -> FrozenSet[str]:
341
341
return frozenset (header .lower () for header in expose_headers )
342
342
343
343
344
- def _get_allow_headers (app : Sanic ) -> FrozenSet [str ]:
344
+ def _get_allow_headers (app : Sanic ) -> frozenset [str ]:
345
345
return _parse_allow_headers (app .config .CORS_ALLOW_HEADERS )
346
346
347
347
348
- def _parse_allow_headers (value : str ) -> FrozenSet [str ]:
348
+ def _parse_allow_headers (value : str ) -> frozenset [str ]:
349
349
allow_headers = (
350
350
(
351
351
value
@@ -372,11 +372,11 @@ def _parse_max_age(value) -> str:
372
372
return str (max_age )
373
373
374
374
375
- def _get_allow_methods (app : Sanic ) -> FrozenSet [str ]:
375
+ def _get_allow_methods (app : Sanic ) -> frozenset [str ]:
376
376
return _parse_allow_methods (app .config .CORS_METHODS )
377
377
378
378
379
- def _parse_allow_methods (value ) -> FrozenSet [str ]:
379
+ def _parse_allow_methods (value ) -> frozenset [str ]:
380
380
allow_methods = (
381
381
(
382
382
value
0 commit comments