Skip to content

Feature: 为内置驱动器请求方法添加 auto_redirects 参数, 以便控制重定向行为 - #4201

Merged
yanyongyu merged 3 commits into
nonebot:masterfrom
Ailitonia:dev
Sep 27, 2026
Merged

yanyongyu merged 3 commits into
nonebot:masterfrom
Ailitonia:dev

Conversation

@Ailitonia

Copy link
Copy Markdown
Contributor

resolve #4200

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Deployed to https://deploy-preview-4201--nonebot2.netlify.app

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.98%. Comparing base (4510ce2) to head (6af7070).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
nonebot/drivers/aiohttp.py 50.00% 1 Missing ⚠️
nonebot/drivers/websockets.py 50.00% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 93.98% <60.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yanyongyu yanyongyu added the enhancement New feature or request label Sep 26, 2026
@yanyongyu

Copy link
Copy Markdown
Member

是不是 websocket 也需要实现一下这个参数?

@Ailitonia

Copy link
Copy Markdown
Contributor Author

是不是 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)

改起来感觉动刀子的地方就有点大了,要不把默认值设成 UNSET 然后在不支持的方法中报 warning 或者抛异常好了(

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@yanyongyu
yanyongyu merged commit adc62bd into nonebot:master Sep 27, 2026
28 of 33 checks passed
@Ailitonia
Ailitonia deleted the dev branch September 27, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

Feature: 为 HTTPClient 等内置驱动器添加用于控制重定向行为的参数

3 participants