mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 11:26:43 +08:00
fix #77, add ua config
This commit is contained in:
parent
1e62b6beca
commit
1254995b3c
@ -137,6 +137,7 @@ sidebar: auto
|
||||
:::
|
||||
|
||||
- `BISON_PROXY`: 使用的代理连接,形如`http://<ip>:<port>`(可选)
|
||||
- `BISON_UA`: 使用的 User-Agent,默认为 Chrome
|
||||
|
||||
## 使用
|
||||
|
||||
|
@ -18,6 +18,7 @@ class PlugConfig(BaseSettings):
|
||||
# 0:不启用;1:首条消息单独发送,剩余照片合并转发;2以及以上:所有消息全部合并转发
|
||||
bison_resend_times: int = 0
|
||||
bison_proxy: Optional[str]
|
||||
bison_ua: str = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
|
||||
|
||||
class Config:
|
||||
extra = "ignore"
|
||||
|
@ -4,9 +4,8 @@ import httpx
|
||||
|
||||
from ..plugin_config import plugin_config
|
||||
|
||||
if plugin_config.bison_proxy:
|
||||
http_client = functools.partial(
|
||||
httpx.AsyncClient, proxies=plugin_config.bison_proxy
|
||||
)
|
||||
else:
|
||||
http_client = httpx.AsyncClient
|
||||
http_client = functools.partial(
|
||||
httpx.AsyncClient,
|
||||
proxies=plugin_config.bison_proxy or None,
|
||||
headers={"user-agent": plugin_config.bison_ua},
|
||||
)
|
||||
|
@ -1,6 +1,5 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
from nonebug.fixture import nonebug_init
|
||||
|
||||
|
||||
async def test_without_proxy(app: App):
|
||||
@ -8,6 +7,8 @@ async def test_without_proxy(app: App):
|
||||
|
||||
c = http_client()
|
||||
assert not c._mounts
|
||||
req = c.build_request("GET", "http://example.com")
|
||||
assert "Chrome" in req.headers["User-Agent"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user