MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / _extract_client_ip

Function _extract_client_ip

fastapi_app/middleware/api_key.py:175–189  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

173
174
175def _extract_client_ip(request: Request) -> str:
176 if settings.SECURITY_TRUST_PROXY_HEADERS:
177 for header_name in ("CF-Connecting-IP", "X-Forwarded-For", "X-Real-IP"):
178 value = (request.headers.get(header_name) or "").strip()
179 if not value:
180 continue
181 if header_name == "X-Forwarded-For":
182 first_hop = value.split(",", 1)[0].strip()
183 if first_hop:
184 return first_hop
185 continue
186 return value
187 if request.client and request.client.host:
188 return str(request.client.host)
189 return "unknown"
190
191
192def _build_rate_limit_key(ip: str, bucket: str) -> str:

Callers 1

dispatchMethod · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected