Repository navigation
Feature: 为内置驱动器请求方法添加 auto_redirects 参数, 以便控制重定向行为 - #4201
Conversation
|
🚀 Deployed to https://deploy-preview-4201--nonebot2.netlify.app |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4201 +/- ##
==========================================
- Coverage 94.02% 93.98% -0.04%
==========================================
Files 49 49
Lines 4536 4541 +5
==========================================
+ Hits 4265 4268 +3
- Misses 271 273 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
是不是 websocket 也需要实现一下这个参数? |
aiohttp 的 ws_connect 目前没有重定向的参数,有人提过不过好像没有动静 (aio-libs/aiohttp#3678) websockets 的话只有一个环境变量 (https://websockets.readthedocs.io/en/15.0.1/reference/variables.html#envvar-WEBSOCKETS_MAX_REDIRECTS) 用来控制重定向次数,请求方法内部是直接默认跟随重定向的 (https://github.com/python-websockets/websockets/blob/main/src/websockets/asyncio/client.py#L448) 改起来感觉动刀子的地方就有点大了,要不把默认值设成 |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
All reviewed changes have no unresolved blocking issues.
Review effort: Lite
Findings: None
What changed in this PR
Adds per-request redirect control for built-in HTTP drivers while preserving default behavior.
Changes:
- Adds
Request.auto_redirects. - Supports redirect control in HTTPX, HTTPX2, and AIOHTTP.
- Adds redirect tests and WebSocket warnings.
| File | Summary |
|---|---|
tests/test_driver.py |
Tests redirect behavior. |
tests/fake_server.py |
Adds a redirect endpoint. |
nonebot/internal/driver/model.py |
Adds the request option. |
nonebot/drivers/websockets.py |
Warns when redirects are ignored. |
nonebot/drivers/httpx2.py |
Applies redirect control. |
nonebot/drivers/httpx.py |
Applies redirect control. |
nonebot/drivers/aiohttp.py |
Applies redirect control. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
resolve #4200