Skip to content

Commit

Permalink
Add middleware to fill in client host
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Sep 13, 2024
1 parent ac32f81 commit 562ce19
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/src/appointment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ async def lifespan(app: FastAPI):
# init app
app = FastAPI(openapi_url=openapi_url, lifespan=lifespan)

@app.middleware("http")
async def apply_x_forwarded_headers_to_client(request: Request, call_next):
ip_list = request.headers.get('x-forwarded-for')
port = request.headers.get('x-forwarded-port')
if ip_list:
client_ip = ip_list.split(',')[0]
request.client.host = client_ip
if port:
request.client.port = port
response = await call_next(request)
return response

app.add_middleware(RawContextMiddleware, plugins=(L10n(),))

# strip html tags from input requests
Expand Down

0 comments on commit 562ce19

Please sign in to comment.