Skip to content

feat(app): add the per-plugin http client - #182

Merged
1morr merged 3 commits into
mainfrom
feat/network-layer
Sep 29, 2026
Merged

1morr merged 3 commits into
mainfrom
feat/network-layer

Conversation

@1morr

@1morr 1morr commented Sep 29, 2026

Copy link
Copy Markdown
Owner

內容

M1 PR 8:網路層(ADR 0012 §決定 1–2、ADR 0011 §決定 4、ADR 0013 §決定 2/4;.trellis/tasks/archive/2026-09/09-29-network-layer/prd.md)。

  • 每插件一個 client(lib/core/network/):攔截器依序是認證、cookie、錯誤對應、限流、網路紀錄。HttpClientAdapter 可以替換,PR 9 的 fixture 錄製與重播接在這裡。
  • 網域:只准 https,而且只能連到允許清單內的網域或其子網域(以點為界)。百分比編碼的 host 一律拒絕。
  • 轉址:手動跟隨,每一跳都檢查網域,最多 5 次。跨 host 時拿掉 Cookie 與 Authorization,並停止注入憑證。方法的轉換照 RFC 9110 §15.4。
  • cookie:每個插件一個記憶體 jar,只存 Domain 涵蓋回應 host 且在允許清單內的 cookie。cookie_jar 本身不檢查 Domain,這點由檢查代理發現並修正。
  • 錯誤:
    • 傳輸錯誤轉成 NetworkError;
    • 429 轉成 RateLimited;503 只有帶可以解析的 Retry-After 時才轉;
    • 其他狀態碼原樣交給插件;
    • 產生的 AppError 帶網路紀錄 id。
  • 重試與限流:重試寫在 client 的迴圈裡,每次嘗試都重跑認證、限流與網路紀錄。另有每插件的併發上限與最小間隔。取消的請求不重試。
  • AuthRequirement:三種標記的判斷,配上「沒有憑證」的來源。CredentialStore 在 M3。
  • 媒體 header 政策:只保留 Referer、User-Agent、Origin、Range,供 PR 10 使用。媒體 client 本身延到 M6:M1 沒有使用者,design §3 已記。
  • 未捕捉錯誤:AppError 走 report 以帶出原因,層級一律是 error。

Review 指南

  • 檢查代理修正的問題,都有變異測試:
    • cookie 替其他 host 設定;
    • Location 解析失敗時丟出非 AppError;
    • 百分比編碼的 host;
    • 時間回撥讓限流卡住。
  • 沒有送出的 required 請求仍會記一筆網路紀錄,AppError 帶著它的 id。
  • ignoreInvalidCookies 維持預設 false,PR 9 接真實 B 站時觀察,已記在 M1 implement。

驗證

app/:

  • format 通過;
  • codegen 沒有變動;
  • dart analyze --fatal-infos、flutter analyze 乾淨;
  • flutter test:303 過、1 跳過(live);
  • fmp_lints 86 過;
  • 哨兵通過。

測試一律用假的 adapter,不聯網。使用者看不到這些改動,真實連線在 PR 9 驗。

Requests reach only the plugin's https hosts, redirects are followed by
hand with every hop checked, cookies stay with the host that set them,
and retries re-run auth, throttling and the network log per attempt.
@1morr
1morr merged commit a54d8fa into main Sep 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant