Skip to content

Commit 5409eae

Browse files
committed
异步httpx封装
1 parent f1bfa6b commit 5409eae

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

app/core/async_sqlmap_api.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import httpx
2+
import os
3+
from dotenv import load_dotenv
4+
5+
load_dotenv()
6+
SQLMAP_API = os.getenv("SQLMAP_API")
7+
AUTH = (os.getenv("SQLMAP_USERNAME"), os.getenv("SQLMAP_PASSWORD")) # Basic Auth
8+
9+
10+
# 异步 HTTP 封装
11+
async def async_get(path: str, timeout=10):
12+
async with httpx.AsyncClient(auth=AUTH, timeout=timeout) as client:
13+
resp = await client.get(f"{SQLMAP_API}{path}")
14+
resp.raise_for_status()
15+
return resp.json()
16+
17+
18+
async def async_post(path: str, json=None, timeout=30):
19+
async with httpx.AsyncClient(auth=AUTH, timeout=timeout) as client:
20+
resp = await client.post(f"{SQLMAP_API}{path}", json=json)
21+
resp.raise_for_status()
22+
return resp.json()
23+
24+
25+
# 异步获取日志
26+
async def async_fetch_sqlmap_logs(task_id: str):
27+
return await async_get(f"/scan/{task_id}/log")
28+
29+
30+
# 异步获取扫描状态
31+
async def async_fetch_sqlmap_status(task_id: str):
32+
return await async_get(f"/scan/{task_id}/status")
33+
34+
35+
# 异步获取扫描结果
36+
async def async_fetch_sqlmap_result(task_id: str):
37+
return await async_get(f"/scan/{task_id}/data")

0 commit comments

Comments
 (0)