Skip to content

Commit

Permalink
增加xff兼容性
Browse files Browse the repository at this point in the history
增加xff兼容性
  • Loading branch information
ljxi committed Oct 23, 2024
1 parent 3fe18c2 commit 8d83671
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ def query():
@app.get("/")
def api(request: Request, ip: str = None):
if not ip:
ip = request.headers.get("x-forwarded-for") or request.headers.get("x-real-ip") or request.client.host
xff = request.headers.get("x-forwarded-for")
if xff:
ip = xff.split(",")[0]
else:
ip = request.headers.get("x-real-ip") or request.client.host
return get_ip_info(ip.strip())

@app.get("/{ip}")
Expand Down

0 comments on commit 8d83671

Please sign in to comment.