This repository was archived by the owner on Jun 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,8 @@ def get_headers_dict(self) -> Dict[str, str]:
236236 try :
237237 name , value = header .decode ("utf-8" ).split (":" , 1 )
238238 headers_dict [name .strip ().lower ()] = value .strip ()
239+ if name == "user-agent" :
240+ logger .debug (f"User-Agent header received: { value } from { self .peername } " )
239241 except ValueError :
240242 continue
241243
Original file line number Diff line number Diff line change 11import traceback
22
33import structlog
4- from fastapi import APIRouter , FastAPI
4+ from fastapi import APIRouter , FastAPI , Request
55from fastapi .middleware .cors import CORSMiddleware
66from fastapi .responses import JSONResponse
77from starlette .middleware .errors import ServerErrorMiddleware
@@ -35,6 +35,15 @@ def init_app(pipeline_factory: PipelineFactory) -> FastAPI:
3535 description = __description__ ,
3636 version = __version__ ,
3737 )
38+
39+ @app .middleware ("http" )
40+ async def log_user_agent (request : Request , call_next ):
41+ user_agent = request .headers .get ("user-agent" )
42+ client_host = request .client .host if request .client else "unknown"
43+ logger .debug (f"User-Agent header received: { user_agent } from { client_host } " )
44+ response = await call_next (request )
45+ return response
46+
3847 app .add_middleware (
3948 CORSMiddleware ,
4049 allow_origins = ["*" ],
You can’t perform that action at this time.
0 commit comments