mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-10-30 12:14:27 +08:00
- docs/dev/plugins.md 改为总览与导航,旧内容拆入 docs/dev/plugins/ - 新增核心概念、配置表单、事件、前端挂载点、命令行、签名与分发、内置插件、示例页 - 每个扩展点一页,侧边栏由页面表生成 - 改正旧文档中下载器配置、hardlink path_map 与补链按钮的过时描述
32 lines
1.1 KiB
Markdown
32 lines
1.1 KiB
Markdown
# HTTP Request (http.request)
|
|
|
|
A transform hook. Every GET request that AB sends (RSS, torrent files, site pages) passes through it. Use it to add a Cookie or to change the User-Agent for a private site. You can change only the headers. AB ignores changes to `url` and `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="Site 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})
|
|
```
|
|
|
|
- The parameter `HttpRequest` has `method`, `url` and `headers`. Return a changed copy, or `None` for no change.
|
|
- AB calls this hook for each request. Keep it light. Do not make network requests in it.
|
|
- Store the Cookie with `secret_field`. The WebUI shows only a mask.
|
|
|
|
Example: `examples/plugins/custom-rss-site`.
|