Coverage for fastid / auth / server.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-18 16:37 +0000

1from typing import Annotated 

2 

3from fastapi import Depends, Request 

4 

5from fastid.auth.config import auth_settings 

6from fastid.core.config import CoreSettings 

7from fastid.core.dependencies import get_core_settings 

8 

9 

10def get_server_url( 

11 request: Request, 

12 settings: CoreSettings = Depends(get_core_settings), 

13) -> str: 

14 if auth_settings.server_url is not None: 

15 return auth_settings.server_url.rstrip("/") 

16 if settings.behind_proxy: 

17 forwarded_host = request.headers.get("X-Forwarded-Host") 

18 forwarded_proto = request.headers.get("X-Forwarded-Proto", "http") 

19 if forwarded_host: 

20 return f"{forwarded_proto}://{forwarded_host}" 

21 base_url = str(request.base_url).rstrip("/") 

22 root_path = str(request.scope.get("root_path", "")).rstrip("/") 

23 if root_path and base_url.endswith(root_path): 

24 return base_url[: -len(root_path)] 

25 return base_url 

26 

27 

28ServerURLDep = Annotated[str, Depends(get_server_url)]