File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 11from typing import Any
22from fastapi import FastAPI
33from fastapi .middleware .cors import CORSMiddleware
4+ import re
5+
6+
7+ def match_origin (origin : str | None , pattern : str ) -> bool :
8+ """
9+ Matches origin against a pattern.
10+ """
11+ return origin is not None and re .match (pattern , origin ) is not None
12+
413
514
615def find_cors_configuration (app : FastAPI , default : Any ) -> Any :
@@ -14,11 +23,14 @@ def find_cors_configuration(app: FastAPI, default: Any) -> Any:
1423 continue
1524
1625 origins = middleware .options .get ("allow_origins" )
17-
18- # Incompatibility fix between CORSMiddleware and python-socketio
19- if origins == ["*" ]:
20- origins = "*"
26+ if origins :
27+ # Incompatibility fix between CORSMiddleware and python-socketio
28+ if origins == ["*" ]:
29+ origins = "*"
30+ return origins
2131
22- return origins
32+ origins_regex = middleware .options .get ("allow_origin_regex" )
33+ if origins_regex :
34+ return lambda origin : match_origin (origin , origins_regex )
2335
2436 return default
You can’t perform that action at this time.
0 commit comments