from fastapi import FastAPI, Header, Depends, HTTPException from fastapi import Request app = FastAPI() @app.get("/headers") async def get_headers(request: Request): headers = dict(request.headers) return {"headers": headers} # 測試: # curl -H "Custom-Header: test_value" http://127.0.0.1:8000/headers