Files
Auto_Bangumi/docs/ja/dev/plugins/points/http-request.md
Estrella Pan 3258fcca4b docs(4.0-P7): 插件开发文档拆分为总览加每个扩展点一页,补齐中英日三语
- docs/dev/plugins.md 改为总览与导航,旧内容拆入 docs/dev/plugins/
- 新增核心概念、配置表单、事件、前端挂载点、命令行、签名与分发、内置插件、示例页
- 每个扩展点一页,侧边栏由页面表生成
- 改正旧文档中下载器配置、hardlink path_map 与补链按钮的过时描述
2026-10-08 14:51:00 +02:00

32 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# HTTP リクエスト (http.request)
transform フックです。AB が送るすべての GET リクエスト(RSS、トレントファイル、サイトのページ)がこのフックを通ります。プライベートサイトへの Cookie の追加や、User-Agent の変更に使います。変更できるのはヘッダーだけです。`url` と `method` の変更は無視されます。
```python
from dataclasses import replace
from pydantic import BaseModel
from ab_sdk import Plugin, hook, points, secret_field
class Options(BaseModel):
cookie: str = secret_field(description="サイトの Cookie")
class PrivateSite(Plugin[Options]):
config_model = Options
@hook(points.HTTP_REQUEST)
def auth(self, request):
if "pt.example.com" not in request.url:
return None
return replace(request, headers={**request.headers, "Cookie": self.config.cookie})
```
- 引数 `HttpRequest` は `method`、`url`、`headers` を持ちます。変更したコピーを返します。`None` は変更なしです。
- AB はリクエストごとにこのフックを呼びます。軽く保ち、中でネットワークリクエストをしないでください。
- Cookie は `secret_field` で保存します。WebUI にはマスクだけが表示されます。
例:`examples/plugins/custom-rss-site`。