[PR #6402] [MERGED] feat(sub): bake Happ/INCY routing profiles into the JSON subscription #6255

Closed
opened 2026-11-02 04:07:25 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6402
Author: @DIMFLIX
Created: 9/3/2026
Status: ✅ Merged
Merged: 9/10/2026
Merged by: @MHSanaei

Base: main ← Head: feat/json-sub-routing


📝 Commits (10+)

  • 4e99a3c feat(sub): parse generic Happ/INCY routing payloads for the JSON subscription
  • 1551046 feat(sub): bake Happ/INCY routing profiles into JSON subscription documents
  • 48cf385 feat(sub): add the subJsonRoutingRules setting
  • 50d697b chore(api): regenerate OpenAPI artifacts for subJsonRoutingRules
  • 87264d2 feat(web): routing profile editor for the JSON subscription
  • f4e6ecf fix(sub): warm and lazily resolve the baked JSON routing source
  • 7cc6d13 feat(sub): fall back to the JSON routing profile for the Routing header
  • 8f8162a Merge remote-tracking branch 'upstream/main' into feat/json-sub-routing
  • 5681e5a fix(sub): pass routingRules arg at call sites added by main
  • d15eca9 Merge remote-tracking branch 'upstream/main' into feat/json-sub-routing

📊 Changes

47 files changed (+1302 additions, -113 deletions)

View changed files

📝 docs/public/openapi.json (+8 -0)
📝 frontend/public/openapi.json (+8 -0)
📝 frontend/src/generated/examples.ts (+2 -0)
📝 frontend/src/generated/schemas.ts (+8 -0)
📝 frontend/src/generated/types.ts (+2 -0)
📝 frontend/src/generated/zod.ts (+2 -0)
📝 frontend/src/models/setting.ts (+1 -0)
📝 frontend/src/pages/settings/SubscriptionFormatsTab.tsx (+14 -0)
📝 frontend/src/pages/settings/SubscriptionGeneralTab.tsx (+2 -6)
➕ frontend/src/pages/settings/subscriptionShared.tsx (+6 -0)
📝 frontend/src/schemas/setting.ts (+1 -0)
📝 internal/sub/controller.go (+29 -17)
📝 internal/sub/external_only_sub_test.go (+1 -1)
📝 internal/sub/host_sub_test.go (+3 -3)
📝 internal/sub/json_flow_gate_test.go (+2 -2)
📝 internal/sub/json_info_node_test.go (+4 -4)
➕ internal/sub/json_routing.go (+366 -0)
➕ internal/sub/json_routing_baked_test.go (+447 -0)
➕ internal/sub/json_routing_test.go (+192 -0)
📝 internal/sub/json_service.go (+50 -9)

...and 27 more files

📄 Description

What

JSON subscription clients that ignore response headers (Happ, INCY — especially with the client-side balancers from #6243/#6304) get no routing at all: the Routing header flow only helps raw/Clash-style subscriptions. This adds an opt-in routing profile that is baked into every JSON subscription document.

New setting: subJsonRoutingRules

Accepts one value, three input forms:

  • inline routing-rules JSON (the generic Happ/INCY payload: DirectSites/ProxySites/BlockSites/*Ip lists, DNS fields, DnsHosts, RouteOrder)
  • a happ://routing/onadd/<base64> or incy://routing/onadd/<base64> deeplink (plain base64; std/URL-safe/padded variants all accepted)
  • an https:// URL — resolved through the existing remote-routing resolver (#6168): TTL cache, ETag revalidation, SSRF guard, warmed by the cron job

When set, it replaces the template's dns and routing.rules in every emitted document — per-inbound docs and client-side balancer docs alike. The balancer document builder already rewrites outboundTag: "proxy" → balancerTag: "balancer", so the profile's proxy rules route into the balancer with zero extra wiring.

Fallback into the Routing header

Happ/INCY fetch the geo files a baked profile references (e.g. geosite:category-ru) through the Routing response header, fed by the existing subRoutingRules setting. When that setting is blank the header stayed unset, so clients fetched no geo files even though a JSON profile was configured. A blank setting now falls back to the JSON profile: happ:///incy:// deeplinks pass through, inline JSON and remote URLs are normalized to a happ:// deeplink via the existing resolver; an unusable or oversized value leaves the header unset (fail-closed). The header fallback is regression-tested for all input forms.

Notes

  • The legacy subJsonRules simple editor keeps working when no profile is set; a profile takes precedence outright.
  • Remote URLs resolve lazily per request with an in-memory memo; a failed resolve is not cached, so a cold-at-startup URL that the cron job later warms takes effect without a restart (regression-tested).
  • Unknown payload keys are ignored (schema-drift tolerance); rule groups follow RouteOrder (default block-direct-proxy).
  • UI: a textarea inside the JSON card on Subscription settings (all 13 locales); the caption documents the header fallback.

Validation

  • go test ./internal/sub/ ./internal/web/job/ — green, incl. new tests: parser table-tests, baked-document tests, balancer-interplay test, cold-remote-warmup regression test, header-fallback tests
  • npm run typecheck / npm run lint / npm run test / npm run build — green
  • OpenAPI artifacts regenerated (make gen + docs sync)
  • End-to-end smoke on a live panel: inline JSON, deeplink, remote URL, balancer doc, broken payload, and the header fallback (JSON body + Routing header verified over HTTP) — all confirmed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6402 **Author:** [@DIMFLIX](https://github.com/DIMFLIX) **Created:** 9/3/2026 **Status:** ✅ Merged **Merged:** 9/10/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/json-sub-routing` --- ### 📝 Commits (10+) - [`4e99a3c`](https://github.com/MHSanaei/3x-ui/commit/4e99a3cc2657cb8f4f37d011937dbdc4a4929348) feat(sub): parse generic Happ/INCY routing payloads for the JSON subscription - [`1551046`](https://github.com/MHSanaei/3x-ui/commit/1551046179c636e7aab2607fa922410f28d1ca7e) feat(sub): bake Happ/INCY routing profiles into JSON subscription documents - [`48cf385`](https://github.com/MHSanaei/3x-ui/commit/48cf3857e4ff62cba5b024c3ac3f8d47b9d1259b) feat(sub): add the subJsonRoutingRules setting - [`50d697b`](https://github.com/MHSanaei/3x-ui/commit/50d697ba447a2c6cb1eb9470c0f06a74505266a6) chore(api): regenerate OpenAPI artifacts for subJsonRoutingRules - [`87264d2`](https://github.com/MHSanaei/3x-ui/commit/87264d28be3eb575753eec879a7dc7f37a395848) feat(web): routing profile editor for the JSON subscription - [`f4e6ecf`](https://github.com/MHSanaei/3x-ui/commit/f4e6ecfbfe425d2ae521300280ef3cfe0471cc58) fix(sub): warm and lazily resolve the baked JSON routing source - [`7cc6d13`](https://github.com/MHSanaei/3x-ui/commit/7cc6d130aa09e89d7d5338f5dca0c73f06390cfc) feat(sub): fall back to the JSON routing profile for the Routing header - [`8f8162a`](https://github.com/MHSanaei/3x-ui/commit/8f8162a7f0fa1fe569bf9d5345939ca16e527c4f) Merge remote-tracking branch 'upstream/main' into feat/json-sub-routing - [`5681e5a`](https://github.com/MHSanaei/3x-ui/commit/5681e5a4503b0d041acf77358a57f0ab50397c1f) fix(sub): pass routingRules arg at call sites added by main - [`d15eca9`](https://github.com/MHSanaei/3x-ui/commit/d15eca9cc6cc87fcd3542307ead08c383e9c03df) Merge remote-tracking branch 'upstream/main' into feat/json-sub-routing ### 📊 Changes **47 files changed** (+1302 additions, -113 deletions) <details> <summary>View changed files</summary> 📝 `docs/public/openapi.json` (+8 -0) 📝 `frontend/public/openapi.json` (+8 -0) 📝 `frontend/src/generated/examples.ts` (+2 -0) 📝 `frontend/src/generated/schemas.ts` (+8 -0) 📝 `frontend/src/generated/types.ts` (+2 -0) 📝 `frontend/src/generated/zod.ts` (+2 -0) 📝 `frontend/src/models/setting.ts` (+1 -0) 📝 `frontend/src/pages/settings/SubscriptionFormatsTab.tsx` (+14 -0) 📝 `frontend/src/pages/settings/SubscriptionGeneralTab.tsx` (+2 -6) ➕ `frontend/src/pages/settings/subscriptionShared.tsx` (+6 -0) 📝 `frontend/src/schemas/setting.ts` (+1 -0) 📝 `internal/sub/controller.go` (+29 -17) 📝 `internal/sub/external_only_sub_test.go` (+1 -1) 📝 `internal/sub/host_sub_test.go` (+3 -3) 📝 `internal/sub/json_flow_gate_test.go` (+2 -2) 📝 `internal/sub/json_info_node_test.go` (+4 -4) ➕ `internal/sub/json_routing.go` (+366 -0) ➕ `internal/sub/json_routing_baked_test.go` (+447 -0) ➕ `internal/sub/json_routing_test.go` (+192 -0) 📝 `internal/sub/json_service.go` (+50 -9) _...and 27 more files_ </details> ### 📄 Description ## What JSON subscription clients that ignore response headers (Happ, INCY — especially with the client-side balancers from #6243/#6304) get no routing at all: the `Routing` header flow only helps raw/Clash-style subscriptions. This adds an opt-in routing profile that is **baked into every JSON subscription document**. ## New setting: `subJsonRoutingRules` Accepts one value, three input forms: - inline routing-rules JSON (the generic Happ/INCY payload: `DirectSites`/`ProxySites`/`BlockSites`/`*Ip` lists, DNS fields, `DnsHosts`, `RouteOrder`) - a `happ://routing/onadd/<base64>` or `incy://routing/onadd/<base64>` deeplink (plain base64; std/URL-safe/padded variants all accepted) - an `https://` URL — resolved through the existing remote-routing resolver (#6168): TTL cache, ETag revalidation, SSRF guard, warmed by the cron job When set, it replaces the template's `dns` and `routing.rules` in **every** emitted document — per-inbound docs and client-side balancer docs alike. The balancer document builder already rewrites `outboundTag: "proxy"` → `balancerTag: "balancer"`, so the profile's proxy rules route into the balancer with zero extra wiring. ## Fallback into the `Routing` header Happ/INCY fetch the geo files a baked profile references (e.g. `geosite:category-ru`) through the `Routing` response header, fed by the existing `subRoutingRules` setting. When that setting is blank the header stayed unset, so clients fetched no geo files even though a JSON profile was configured. A blank setting now falls back to the JSON profile: `happ://`/`incy://` deeplinks pass through, inline JSON and remote URLs are normalized to a `happ://` deeplink via the existing resolver; an unusable or oversized value leaves the header unset (fail-closed). The header fallback is regression-tested for all input forms. ## Notes - The legacy `subJsonRules` simple editor keeps working when no profile is set; a profile takes precedence outright. - Remote URLs resolve lazily per request with an in-memory memo; a failed resolve is not cached, so a cold-at-startup URL that the cron job later warms takes effect without a restart (regression-tested). - Unknown payload keys are ignored (schema-drift tolerance); rule groups follow `RouteOrder` (default `block-direct-proxy`). - UI: a textarea inside the JSON card on Subscription settings (all 13 locales); the caption documents the header fallback. ## Validation - `go test ./internal/sub/ ./internal/web/job/` — green, incl. new tests: parser table-tests, baked-document tests, balancer-interplay test, cold-remote-warmup regression test, header-fallback tests - `npm run typecheck` / `npm run lint` / `npm run test` / `npm run build` — green - OpenAPI artifacts regenerated (`make gen` + docs sync) - End-to-end smoke on a live panel: inline JSON, deeplink, remote URL, balancer doc, broken payload, and the header fallback (JSON body + `Routing` header verified over HTTP) — all confirmed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:25 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6255
No description provided.