Skip to content

Commit

Permalink
<global>[feat]proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
HornCopper committed Aug 5, 2024
1 parent 2c2dc76 commit 8c184a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/tools/config/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bot_basic: # Bot 基础类信息
bot_notice: # Bot 事件通知
"":
"" # Bot QQ号: Bot 通知群号 (string: string)
proxy: "" # 代理服务器

github: # GitHub 相关配置
web_path: "" # Webhook 接收路径
Expand Down
14 changes: 9 additions & 5 deletions src/tools/utils/request.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
from src.tools.config import Config

proxy = Config.bot_basic.proxy

import httpx

async def get_url(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False, proxy=proxy) as client:
resp = await client.get(url, **kwargs)
result = resp.text
return result

async def get_content(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False, proxy=proxy) as client:
resp = await client.get(url, **kwargs)
result = resp.content
return result

async def get_status(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False, proxy=proxy) as client:
resp = await client.get(url, **kwargs)
result = resp.status_code
return result

async def get_api(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False, proxy=proxy) as client:
resp = await client.get(url, **kwargs)
result = resp.json()
return result

async def post_url(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False, proxy=proxy) as client:
resp = await client.post(url, **kwargs)
result = resp.text
return result

0 comments on commit 8c184a1

Please sign in to comment.