mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 20:40:13 +03:00
fix(symbols): add CORS headers to symbol file responses
FileResponse does not properly include CORS headers when served from a different origin. This fix manually adds the Access-Control-Allow-Origin header based on the request origin. Fixes CORS policy errors when accessing symbol files from frontend applications running on localhost:4200 or other origins.
This commit is contained in:
parent
ae8ef84668
commit
8041d2906c
@ -61,7 +61,7 @@ def get_symbols() -> List[dict]:
|
||||
# FIXME: this is a temporary workaround due to a bug in the web-ui: https://github.com/GNS3/gns3-web-ui/issues/1466
|
||||
# dependencies=[Depends(has_privilege("Symbol.Audit"))]
|
||||
)
|
||||
async def get_symbol(symbol_id: str) -> FileResponse:
|
||||
async def get_symbol(symbol_id: str, request: Request) -> Response:
|
||||
"""
|
||||
Download a symbol file.
|
||||
|
||||
@ -71,7 +71,12 @@ async def get_symbol(symbol_id: str) -> FileResponse:
|
||||
controller = Controller.instance()
|
||||
try:
|
||||
symbol = controller.symbols.get_path(symbol_id)
|
||||
return FileResponse(symbol)
|
||||
return FileResponse(
|
||||
symbol,
|
||||
headers={
|
||||
"Access-Control-Allow-Origin": request.headers.get("origin", "*"),
|
||||
}
|
||||
)
|
||||
except (KeyError, OSError) as e:
|
||||
raise ControllerNotFoundError(f"Could not get symbol file: {e}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user