dane w headerach i inne funkcje
This commit is contained in:
25
app/api.py
25
app/api.py
@@ -159,21 +159,24 @@ def get_client_ip(request: Request) -> str:
|
||||
return "0.0.0.0"
|
||||
|
||||
|
||||
@router.get("/ip")
|
||||
@router.api_route('/ip', methods=["GET", "HEAD"])
|
||||
async def my_ip(request: Request, geo=Depends(get_geo)):
|
||||
ip = get_client_ip(request)
|
||||
data = geo.lookup(ip)
|
||||
return Response(
|
||||
content=data.__str__(), media_type="application/json", headers=geo_headers(data)
|
||||
)
|
||||
ip = get_client_ip(request) # pobieranie IP:contentReference[oaicite:0]{index=0}
|
||||
data = geo.lookup(ip) # geo lookup:contentReference[oaicite:1]{index=1}:contentReference[oaicite:2]{index=2}
|
||||
headers = _geo_headers(data)
|
||||
if request.method == "HEAD":
|
||||
return Response(status_code=200, headers=headers)
|
||||
body = json.dumps(data, ensure_ascii=False) + "\n"
|
||||
return Response(content=body, media_type="application/json", headers=headers)
|
||||
|
||||
|
||||
@router.get("/ip/{ip_address}")
|
||||
@router.api_route('/ip/{ip_address}', methods=["GET", "HEAD"])
|
||||
async def ip_lookup(ip_address: str, geo=Depends(get_geo)):
|
||||
data = geo.lookup(ip_address)
|
||||
return Response(
|
||||
content=data.__str__(), media_type="application/json", headers=geo_headers(data)
|
||||
)
|
||||
headers = _geo_headers(data)
|
||||
if request.method == "HEAD":
|
||||
return Response(status_code=200, headers=headers)
|
||||
body = json.dumps(data, ensure_ascii=False) + "\n"
|
||||
return Response(content=body, media_type="application/json", headers=headers)
|
||||
|
||||
|
||||
@router.post("/reload")
|
||||
|
Reference in New Issue
Block a user