[GH-ISSUE #6322] [Feature]: Named routing profiles, assignable to inbounds and hosts #4296

Open
opened 2026-10-31 20:38:37 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @den41apple on GitHub (Aug 25, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6322

All routing settings for subscriptions are global to the panel:

  • subEnableRouting / subRoutingRules go into the Routing-Enable / Routing headers (internal/sub/controller.go:733-772, ApplyCommonHeaders)
  • subIncyEnableRouting / subIncyRoutingRules are appended verbatim to the raw body (internal/sub/controller.go:418-421)
  • subJsonRules is merged into routing.rules once, in the service constructor, before any request is served (internal/sub/json_service.go:41-49)

So a panel can hand out one routing profile and nothing else. I cannot say "this entry uses profile A, that entry uses profile B". I also cannot store a profile once and reuse it: the rules live as an opaque blob inside a single settings field, and if I want them in two places I paste them twice.

Note that a routing profile already has a name, and clients use that name to recognise the profile and update it independently of the others. It behaves like an object everywhere except in the panel, where it is a text field.

For JSON subscriptions the limitation is not just missing UI. Every array element is a full xray config that the client passes to the core as-is, so it could carry its own routing section. But GetJson builds each element with a shallow copy:

newConfigJson := make(map[string]any)
maps.Copy(newConfigJson, s.configJson)   // internal/sub/json_service.go:242-243

newConfigJson["outbounds"] = newOutbounds
newConfigJson["remarks"]   = subReq.endpointRemark(...)

Only outbounds and remarks get replaced. routing is not just identical in every element, it is the same map[string]any behind the same pointer. Mutating it for one entry would corrupt the rest, so right now there is no way to express per-entry routing at all.

Describe the solution you'd like

Make routing profiles named objects that can be assigned to inbounds and to hosts. The override chain is the same one the panel already uses for FinalMask (global default, per-host override) and for ExcludeFromSubTypes, except the payload is stored once instead of being copied into every place that needs it.

This splits into two phases. Phase 1 is useful on its own if phase 2 is not wanted.

Phase 1: the profile object

New table routing_profiles:

type RoutingProfile struct {
    Id     int    `json:"id" gorm:"primaryKey;autoIncrement"`
    Name   string `json:"name" gorm:"uniqueIndex;not null" validate:"required,max=64"`
    Remark string `json:"remark" validate:"omitempty,max=256"`

    // Deeplink form, used by raw subscriptions:
    // happ://routing/add/<base64>, incy://routing/onadd/<base64>, ...
    Deeplink string `json:"deeplink" gorm:"type:text"`

    // JSON array of xray routing rules, used by JSON subscriptions.
    // Same shape as the existing global subJsonRules.
    JsonRules string `json:"jsonRules" gorm:"type:text"`

    IsDefault bool `json:"isDefault" gorm:"default:false"`
    IsEnabled bool `json:"isEnabled" gorm:"default:true"`

    CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"`
    UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"`
}

One row covers both delivery channels, so the rules are edited in one place and every subscription that references the profile picks up the change.

CRUD under /panel/api/routing-profiles (list, get/:id, add, update/:id, del/:id, setEnable/:id), same shape as the host controller (internal/web/controller/host.go:24-36).

Phase 2: assignment

Join table routing_profile_bindings:

ProfileId int    // -> routing_profiles.id
Scope     string // "global" | "inbound" | "host"
TargetId  int    // inbound id or host id, ignored for "global"

Resolution for a subscription entry, most specific first:

host bindings -> inbound bindings -> global bindings -> current settings

The last step keeps installs that never create a profile working exactly as they do now.

The relation is many-to-many on purpose. One entry can legitimately offer more than one profile and let the user pick in the client.

Behaviour per subscription format

  1. Raw. Append the Deeplink of every profile resolved for the entries of this subscription, after the share links and before the existing global subIncyRoutingRules, de-duplicated by name. Several routing links in one body are already valid and the panel already writes one that way, so there is nothing to resolve here.
  2. JSON. Deep-copy configJson["routing"] per entry (needed anyway, see above), then use JsonRules of the resolved profile instead of the global subJsonRules. An element can hold only one routing, so if several profiles resolve to one entry, the one flagged IsDefault wins and the others are skipped for that element.
  3. Clash. Same single-list constraint as JSON (internal/sub/clash_service.go:90-104): take the IsDefault profile, otherwise inherit global. Fine to leave for later.
  4. Routing header. Stays global, unchanged. Only one header can be sent, so a per-entry value means nothing there. This is the ambiguity that killed #4479.

Edge cases

  • No profiles defined: current behaviour, unchanged.
  • Profile filled in one channel only (say Deeplink set, JsonRules empty): that channel inherits the global setting, the other one still applies.
  • Several profiles on one entry: raw emits all of them, JSON and Clash take IsDefault.
  • Deleting a profile cascades its bindings, and affected entries fall back down the chain.
  • Works together with ExcludeFromSubTypes, so a whitelist-only entry can go to JSON clients and stay hidden from raw ones.

Migration

One migration for the two tables. Optionally a non-empty subRoutingRules or subIncyRoutingRules can be lifted into a single profile bound at global scope, which makes the upgrade invisible to current operators.

UI

  • New page "Routing profiles" with name, remark, deeplink, JSON rules and the default flag. Same CRUD layout as Hosts.
  • A multi-select in frontend/src/pages/hosts/HostFormModal.tsx and in the inbound form, labelled "Routing profiles, leave empty to inherit".

Alternatives you've considered

A plain text field on the host. That was my first idea and it does work, but the same base64 blob ends up stored in every host that needs it. With 15 nodes and two entries each, changing one rule set means editing about 30 fields by hand. A named object avoids that and gives the panel the name the clients already rely on.

A field on the inbound (#4479). Does not cover my own setup. One server is reachable directly and through a relay in Russia, and those are two hosts of the same inbound. An inbound-level field cannot tell them apart, and that is exactly the pair that needs different routing.

A second panel plus external subscription merge. This does deliver two profiles: raw external subscription bodies are copied line by line with the only filter being strings.Contains(ln, "://") (internal/sub/external_subscription.go:148-168), so a routing deeplink from a second panel does reach the client. But it costs a second xray process, a second database, a second backup and upgrade path, plus a port conflict to sort out, and it still cannot bind a profile to a specific entry. It also fails for JSON and Clash, where external links go through link.ParseLink and non-share schemes are dropped (json_service.go:96-100, clash_external.go:14-18).

A reverse proxy rewriting the Routing header. Covers the header only. It needs a separate subscription URL per profile, so the same person ends up with duplicate server lists, and it does nothing for JSON subscriptions where routing sits inside the config.

One shared profile for everyone. Whitelist users get broad rules or everyone else gets narrow ones. That is what I run today and it is why I am writing this.

Concrete use case

I run about 15 nodes and hand out one subscription per client, roughly 300 clients.

Russian mobile carriers periodically cut everything except a government "white list" of some 500 domains: banks, government services, marketplaces. During a cut those domains have to go direct, because they are the only ones that still resolve. Route them through the tunnel and they go down with it. Outside a cut the same person wants the usual split, all of Russia direct and the rest proxied. Two rule sets, both needed by the same people.

On top of that every server is published twice, once directly and once through a relay hosted in Russia. Those two entries share one inbound and one UUID, only the path differs, and they need different routing because the relay is what survives a cut. So assignment has to reach the host level, while still being convenient to apply in bulk on the inbound. That is why both scopes are in the proposal.

Today I ask each of those 300 people to import a second routing deeplink by hand and switch it in app settings, because the panel can attach one profile to the subscription it serves and no more. With named profiles I define "normal" and "white list" once, bind them to the right hosts, and the choice becomes one tap in the client.

Mockups, screenshots, or examples

Profiles, defined once:

Name Deeplink JSON rules Default
normal happ://routing/add/eyJOYW1lIjoi… [ ... ] yes
white-list happ://routing/add/eyJOYW1lIjoi… [ ... ] no

Bound to entries of one inbound:

Host Remark Profiles
host A NL-1 normal
host B NL-1 (relay) normal, white-list
host C NL-1 (white list) white-list

Resulting raw body, before base64:

vless://…#NL-1
vless://…#NL-1%20(relay)
vless://…#NL-1%20(white%20list)
happ://routing/add/…      <- normal
happ://routing/add/…      <- white-list, de-duplicated across entries

Resulting JSON subscription: three array elements, identical except remarks, outbounds and, with this feature, routing, each taking the IsDefault profile bound to its host.

Relation to #4479

I opened #4479 myself and it was closed. This one is deliberately different, because the old request was under-specified:

  • Level. #4479 asked for the field on the inbound only. My own setup breaks that: a direct entry and a relayed entry are two hosts of one inbound and need different routing. Both scopes are needed, with host winning over inbound.
  • Channels. #4479 treated "header or body" as interchangeable. They are not. The header carries one profile, the body carries many, and separating them removes the conflict for raw subscriptions.
  • JSON. #4479 said nothing about JSON subscriptions, which is where the limitation is structural, since routing is shared by pointer across entries.
  • Shape. #4479 proposed an opaque blob per inbound. This proposes a named object, which is what the clients already assume exists.

Happy to close this one in favour of reopening #4479 if you prefer that thread.

Which parts of the panel would this affect?

Subscription (share links / Clash / JSON), Backend (API endpoints, login, settings), Frontend (UI / panel pages), Database / migrations

Which parts of the panel would this affect?

Subscription (share links / Clash / JSON), Backend (API endpoints, login, settings), Frontend (UI / panel pages), Database / migrations

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @den41apple on GitHub (Aug 25, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6322 ### Is your feature request related to a problem? All routing settings for subscriptions are global to the panel: - `subEnableRouting` / `subRoutingRules` go into the `Routing-Enable` / `Routing` headers (`internal/sub/controller.go:733-772`, `ApplyCommonHeaders`) - `subIncyEnableRouting` / `subIncyRoutingRules` are appended verbatim to the raw body (`internal/sub/controller.go:418-421`) - `subJsonRules` is merged into `routing.rules` once, in the service constructor, before any request is served (`internal/sub/json_service.go:41-49`) So a panel can hand out one routing profile and nothing else. I cannot say "this entry uses profile A, that entry uses profile B". I also cannot store a profile once and reuse it: the rules live as an opaque blob inside a single settings field, and if I want them in two places I paste them twice. Note that a routing profile already has a name, and clients use that name to recognise the profile and update it independently of the others. It behaves like an object everywhere except in the panel, where it is a text field. For JSON subscriptions the limitation is not just missing UI. Every array element is a full xray config that the client passes to the core as-is, so it could carry its own `routing` section. But `GetJson` builds each element with a shallow copy: ```go newConfigJson := make(map[string]any) maps.Copy(newConfigJson, s.configJson) // internal/sub/json_service.go:242-243 newConfigJson["outbounds"] = newOutbounds newConfigJson["remarks"] = subReq.endpointRemark(...) ``` Only `outbounds` and `remarks` get replaced. `routing` is not just identical in every element, it is the same `map[string]any` behind the same pointer. Mutating it for one entry would corrupt the rest, so right now there is no way to express per-entry routing at all. ### Describe the solution you'd like Make routing profiles named objects that can be assigned to inbounds and to hosts. The override chain is the same one the panel already uses for `FinalMask` (global default, per-host override) and for `ExcludeFromSubTypes`, except the payload is stored once instead of being copied into every place that needs it. This splits into two phases. Phase 1 is useful on its own if phase 2 is not wanted. #### Phase 1: the profile object New table `routing_profiles`: ```go type RoutingProfile struct { Id int `json:"id" gorm:"primaryKey;autoIncrement"` Name string `json:"name" gorm:"uniqueIndex;not null" validate:"required,max=64"` Remark string `json:"remark" validate:"omitempty,max=256"` // Deeplink form, used by raw subscriptions: // happ://routing/add/<base64>, incy://routing/onadd/<base64>, ... Deeplink string `json:"deeplink" gorm:"type:text"` // JSON array of xray routing rules, used by JSON subscriptions. // Same shape as the existing global subJsonRules. JsonRules string `json:"jsonRules" gorm:"type:text"` IsDefault bool `json:"isDefault" gorm:"default:false"` IsEnabled bool `json:"isEnabled" gorm:"default:true"` CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"` UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` } ``` One row covers both delivery channels, so the rules are edited in one place and every subscription that references the profile picks up the change. CRUD under `/panel/api/routing-profiles` (`list`, `get/:id`, `add`, `update/:id`, `del/:id`, `setEnable/:id`), same shape as the host controller (`internal/web/controller/host.go:24-36`). #### Phase 2: assignment Join table `routing_profile_bindings`: ```go ProfileId int // -> routing_profiles.id Scope string // "global" | "inbound" | "host" TargetId int // inbound id or host id, ignored for "global" ``` Resolution for a subscription entry, most specific first: ``` host bindings -> inbound bindings -> global bindings -> current settings ``` The last step keeps installs that never create a profile working exactly as they do now. The relation is many-to-many on purpose. One entry can legitimately offer more than one profile and let the user pick in the client. #### Behaviour per subscription format 1. **Raw.** Append the `Deeplink` of every profile resolved for the entries of this subscription, after the share links and before the existing global `subIncyRoutingRules`, de-duplicated by name. Several routing links in one body are already valid and the panel already writes one that way, so there is nothing to resolve here. 2. **JSON.** Deep-copy `configJson["routing"]` per entry (needed anyway, see above), then use `JsonRules` of the resolved profile instead of the global `subJsonRules`. An element can hold only one `routing`, so if several profiles resolve to one entry, the one flagged `IsDefault` wins and the others are skipped for that element. 3. **Clash.** Same single-list constraint as JSON (`internal/sub/clash_service.go:90-104`): take the `IsDefault` profile, otherwise inherit global. Fine to leave for later. 4. **`Routing` header.** Stays global, unchanged. Only one header can be sent, so a per-entry value means nothing there. This is the ambiguity that killed #4479. #### Edge cases - No profiles defined: current behaviour, unchanged. - Profile filled in one channel only (say `Deeplink` set, `JsonRules` empty): that channel inherits the global setting, the other one still applies. - Several profiles on one entry: raw emits all of them, JSON and Clash take `IsDefault`. - Deleting a profile cascades its bindings, and affected entries fall back down the chain. - Works together with `ExcludeFromSubTypes`, so a whitelist-only entry can go to JSON clients and stay hidden from raw ones. #### Migration One migration for the two tables. Optionally a non-empty `subRoutingRules` or `subIncyRoutingRules` can be lifted into a single profile bound at global scope, which makes the upgrade invisible to current operators. #### UI - New page "Routing profiles" with name, remark, deeplink, JSON rules and the default flag. Same CRUD layout as Hosts. - A multi-select in `frontend/src/pages/hosts/HostFormModal.tsx` and in the inbound form, labelled "Routing profiles, leave empty to inherit". ### Alternatives you've considered **A plain text field on the host.** That was my first idea and it does work, but the same base64 blob ends up stored in every host that needs it. With 15 nodes and two entries each, changing one rule set means editing about 30 fields by hand. A named object avoids that and gives the panel the name the clients already rely on. **A field on the inbound (#4479).** Does not cover my own setup. One server is reachable directly and through a relay in Russia, and those are two hosts of the same inbound. An inbound-level field cannot tell them apart, and that is exactly the pair that needs different routing. **A second panel plus external subscription merge.** This does deliver two profiles: raw external subscription bodies are copied line by line with the only filter being `strings.Contains(ln, "://")` (`internal/sub/external_subscription.go:148-168`), so a routing deeplink from a second panel does reach the client. But it costs a second xray process, a second database, a second backup and upgrade path, plus a port conflict to sort out, and it still cannot bind a profile to a specific entry. It also fails for JSON and Clash, where external links go through `link.ParseLink` and non-share schemes are dropped (`json_service.go:96-100`, `clash_external.go:14-18`). **A reverse proxy rewriting the `Routing` header.** Covers the header only. It needs a separate subscription URL per profile, so the same person ends up with duplicate server lists, and it does nothing for JSON subscriptions where routing sits inside the config. **One shared profile for everyone.** Whitelist users get broad rules or everyone else gets narrow ones. That is what I run today and it is why I am writing this. ### Concrete use case I run about 15 nodes and hand out one subscription per client, roughly 300 clients. Russian mobile carriers periodically cut everything except a government "white list" of some 500 domains: banks, government services, marketplaces. During a cut those domains have to go direct, because they are the only ones that still resolve. Route them through the tunnel and they go down with it. Outside a cut the same person wants the usual split, all of Russia direct and the rest proxied. Two rule sets, both needed by the same people. On top of that every server is published twice, once directly and once through a relay hosted in Russia. Those two entries share one inbound and one UUID, only the path differs, and they need different routing because the relay is what survives a cut. So assignment has to reach the host level, while still being convenient to apply in bulk on the inbound. That is why both scopes are in the proposal. Today I ask each of those 300 people to import a second routing deeplink by hand and switch it in app settings, because the panel can attach one profile to the subscription it serves and no more. With named profiles I define "normal" and "white list" once, bind them to the right hosts, and the choice becomes one tap in the client. ### Mockups, screenshots, or examples Profiles, defined once: | Name | Deeplink | JSON rules | Default | |--------------|------------------------------------|------------|---------| | `normal` | `happ://routing/add/eyJOYW1lIjoi…` | `[ ... ]` | yes | | `white-list` | `happ://routing/add/eyJOYW1lIjoi…` | `[ ... ]` | no | Bound to entries of one inbound: | Host | Remark | Profiles | |--------|---------------------|------------------------| | host A | `NL-1` | `normal` | | host B | `NL-1 (relay)` | `normal`, `white-list` | | host C | `NL-1 (white list)` | `white-list` | Resulting raw body, before base64: ``` vless://…#NL-1 vless://…#NL-1%20(relay) vless://…#NL-1%20(white%20list) happ://routing/add/… <- normal happ://routing/add/… <- white-list, de-duplicated across entries ``` Resulting JSON subscription: three array elements, identical except `remarks`, `outbounds` and, with this feature, `routing`, each taking the `IsDefault` profile bound to its host. ### Relation to #4479 I opened #4479 myself and it was closed. This one is deliberately different, because the old request was under-specified: - **Level.** #4479 asked for the field on the inbound only. My own setup breaks that: a direct entry and a relayed entry are two hosts of one inbound and need different routing. Both scopes are needed, with host winning over inbound. - **Channels.** #4479 treated "header or body" as interchangeable. They are not. The header carries one profile, the body carries many, and separating them removes the conflict for raw subscriptions. - **JSON.** #4479 said nothing about JSON subscriptions, which is where the limitation is structural, since `routing` is shared by pointer across entries. - **Shape.** #4479 proposed an opaque blob per inbound. This proposes a named object, which is what the clients already assume exists. Happy to close this one in favour of reopening #4479 if you prefer that thread. ### Which parts of the panel would this affect? Subscription (share links / Clash / JSON), Backend (API endpoints, login, settings), Frontend (UI / panel pages), Database / migrations ### Which parts of the panel would this affect? Subscription (share links / Clash / JSON), Backend (API endpoints, login, settings), Frontend (UI / panel pages), Database / migrations ### Are you willing to help? - [x] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 25, 2026):

This is the same request as #6297 — the body is identical, and you closed that one nine seconds before opening this (closedAt 2026-08-25T13:59:23Z vs this issue's createdAt 2026-08-25T13:59:32Z). The analysis posted there still stands, so I won't repeat it; because #6297 is closed, I am leaving this thread open as the live one rather than closing it back onto a dead issue. Nothing has changed at the tip (f727d04f, v3.7.0): Routing does not appear anywhere in internal/database/model/model.go, so there is still no per-inbound or per-host routing override in the schema, and #4479 closed on 2026-05-29 with an empty closedByPullRequestsReferences — nothing was implemented for it.

Your anchors, re-checked at the current tip (the line numbers have drifted, the claims have not):

your claim anchor now
Happ header is panel-wide resolveRoutingSource(remoteRoutingHapp, profileRoutingRules) — internal/sub/controller.go:843-849, inside ApplyCommonHeaders (:812-853), fed the global fields at :429
Incy rules appended verbatim internal/sub/controller.go:431-437
subJsonRules merged once in the constructor internal/sub/json_service.go:48-55
entries are a shallow copy, only outbounds/remarks replaced internal/sub/json_service.go:545-549 (per client) and :143-145 (external links)
Clash carries one rule list "rules": []string{"MATCH,PROXY"} at internal/sub/clash_service.go:98, merged globally at :101-109
FinalMask is the precedent internal/database/model/model.go:1094-1096 → internal/sub/host_sub.go:105 → :150
external-sub line filter if strings.Contains(ln, "://") is at internal/sub/external_subscription.go:197, not 148-168

Two implementation facts on top of that write-up, which change where the work lands:

1. The JSON substitution cannot happen where you put it. NewSubJsonService is constructed exactly once in production (internal/sub/controller.go:251) and folds the global rules straight into the base document:

// internal/sub/json_service.go:48-55
if rules != "" {
    var newRules []any
    routing, _ := configJson["routing"].(map[string]any)
    defaultRules, _ := routing["rules"].([]any)
    _ = json.Unmarshal([]byte(rules), &newRules)
    defaultRules = append(newRules, defaultRules...)
    routing["rules"] = defaultRules
    configJson["routing"] = routing
}

By the time an entry is rendered, s.configJson["routing"]["rules"] is global rules + the catch-all from internal/sub/default.json:81-87 ({"type":"field","network":"tcp,udp","outboundTag":"proxy"}), and the un-merged base no longer exists. So "use JsonRules of the resolved profile instead of the global subJsonRules" cannot be expressed as a per-entry overwrite of routing — the constructor has to keep the pristine rules (or the pristine routing subtree) in a field first. Small change, but it belongs in NewSubJsonService, not in the renderer.

2. Raw is the expensive channel; JSON is nearly free. For JSON and Clash, per-host values already ride to the renderer through the endpoint map — ep["finalMask"] = h.FinalMask at internal/sub/host_sub.go:105, consumed at :150 — which is why finalMask cost so little. Raw has no such channel: hostEndpoints is called and consumed locally inside getSubs (internal/sub/service.go:323), and the signature is

// internal/sub/service.go:296
func (s *SubService) getSubs(subId string) ([]string, []string, int64, xray.ClientTraffic, error)

so the controller that would append the deeplink (internal/sub/controller.go:419-437) never sees a host. Phase 2's raw half needs a new value out of getSubs; the JSON half does not.

Worth restating because it cuts the other way: the per-entry deep copy you ask for already exists for one document kind. The client-side balancer path added in da01b763 clones routing and each rule map per document (internal/sub/json_service.go:392-396, assigned at :430) under the comment "The routing subtree in s.configJson is shared by every emitted document; clone it (and each rule map) before pointing rules at the balancer." That is generalisation, not new machinery — and note it is a latent hazard, not a live output bug: each element is marshalled immediately and nothing mutates routing on the per-inbound path today.

Related, and I am leaving both open: #5824 asks for the inbound-level JSON subset of this (a "Routing" tab in the inbound editor) — it overlaps heavily enough that whoever decides one should decide both, but the scope differs and neither obviously satisfies the other. #6062 splits routing by client User-Agent, a different axis.

One thing I still cannot check from here: whether Happ and Incy really keep several routing/add deeplinks from a single subscription body as separate, independently selectable profiles. That is client-side behaviour outside this repository, and the entire raw half of the proposal rests on it; a report of two profiles landing side by side in the client from one body would settle it.

Verdict: Feature request

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5411566660 --> @github-actions[bot] commented on GitHub (Aug 25, 2026): This is the same request as #6297 — the body is identical, and you closed that one nine seconds before opening this (`closedAt` `2026-08-25T13:59:23Z` vs this issue's `createdAt` `2026-08-25T13:59:32Z`). The analysis posted there still stands, so I won't repeat it; because #6297 is closed, I am leaving **this** thread open as the live one rather than closing it back onto a dead issue. Nothing has changed at the tip (`f727d04f`, v3.7.0): `Routing` does not appear anywhere in `internal/database/model/model.go`, so there is still no per-inbound or per-host routing override in the schema, and #4479 closed on 2026-05-29 with an empty `closedByPullRequestsReferences` — nothing was implemented for it. **Your anchors, re-checked at the current tip** (the line numbers have drifted, the claims have not): | your claim | anchor now | | --- | --- | | Happ header is panel-wide | `resolveRoutingSource(remoteRoutingHapp, profileRoutingRules)` — `internal/sub/controller.go:843-849`, inside `ApplyCommonHeaders` (`:812-853`), fed the global fields at `:429` | | Incy rules appended verbatim | `internal/sub/controller.go:431-437` | | `subJsonRules` merged once in the constructor | `internal/sub/json_service.go:48-55` | | entries are a shallow copy, only `outbounds`/`remarks` replaced | `internal/sub/json_service.go:545-549` (per client) and `:143-145` (external links) | | Clash carries one rule list | `"rules": []string{"MATCH,PROXY"}` at `internal/sub/clash_service.go:98`, merged globally at `:101-109` | | `FinalMask` is the precedent | `internal/database/model/model.go:1094-1096` → `internal/sub/host_sub.go:105` → `:150` | | external-sub line filter | `if strings.Contains(ln, "://")` is at `internal/sub/external_subscription.go:197`, not `148-168` | **Two implementation facts on top of that write-up, which change where the work lands:** **1. The JSON substitution cannot happen where you put it.** `NewSubJsonService` is constructed exactly once in production (`internal/sub/controller.go:251`) and folds the global rules straight into the base document: ```go // internal/sub/json_service.go:48-55 if rules != "" { var newRules []any routing, _ := configJson["routing"].(map[string]any) defaultRules, _ := routing["rules"].([]any) _ = json.Unmarshal([]byte(rules), &newRules) defaultRules = append(newRules, defaultRules...) routing["rules"] = defaultRules configJson["routing"] = routing } ``` By the time an entry is rendered, `s.configJson["routing"]["rules"]` is *global rules + the catch-all* from `internal/sub/default.json:81-87` (`{"type":"field","network":"tcp,udp","outboundTag":"proxy"}`), and the un-merged base no longer exists. So "use `JsonRules` of the resolved profile instead of the global `subJsonRules`" cannot be expressed as a per-entry overwrite of `routing` — the constructor has to keep the pristine rules (or the pristine `routing` subtree) in a field first. Small change, but it belongs in `NewSubJsonService`, not in the renderer. **2. Raw is the expensive channel; JSON is nearly free.** For JSON and Clash, per-host values already ride to the renderer through the endpoint map — `ep["finalMask"] = h.FinalMask` at `internal/sub/host_sub.go:105`, consumed at `:150` — which is why `finalMask` cost so little. Raw has no such channel: `hostEndpoints` is called and consumed locally inside `getSubs` (`internal/sub/service.go:323`), and the signature is ```go // internal/sub/service.go:296 func (s *SubService) getSubs(subId string) ([]string, []string, int64, xray.ClientTraffic, error) ``` so the controller that would append the deeplink (`internal/sub/controller.go:419-437`) never sees a host. Phase 2's raw half needs a new value out of `getSubs`; the JSON half does not. Worth restating because it cuts the other way: the per-entry deep copy you ask for already exists for one document kind. The client-side balancer path added in `da01b763` clones `routing` and each rule map per document (`internal/sub/json_service.go:392-396`, assigned at `:430`) under the comment *"The routing subtree in `s.configJson` is shared by every emitted document; clone it (and each rule map) before pointing rules at the balancer."* That is generalisation, not new machinery — and note it is a latent hazard, not a live output bug: each element is marshalled immediately and nothing mutates `routing` on the per-inbound path today. **Related, and I am leaving both open:** #5824 asks for the inbound-level JSON subset of this (a "Routing" tab in the inbound editor) — it overlaps heavily enough that whoever decides one should decide both, but the scope differs and neither obviously satisfies the other. #6062 splits routing by client User-Agent, a different axis. One thing I still cannot check from here: whether Happ and Incy really keep several `routing/add` deeplinks from a single subscription body as separate, independently selectable profiles. That is client-side behaviour outside this repository, and the entire raw half of the proposal rests on it; a report of two profiles landing side by side in the client from one body would settle it. Verdict: Feature request *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@den41apple commented on GitHub (Aug 26, 2026):

I went and tested it. Short answer: yes, Happ keeps them as separate profiles.

Setup was Happ Desktop 4.1.1 (602) on Windows, pointed at a local http server returning a plain text body:

happ://routing/add/<base64 of {"Name":"HW-TEST-A", ..., "DomainStrategy":"AsIs"}>
happ://routing/add/<base64 of {"Name":"HW-TEST-B", ..., "DomainStrategy":"IPIfNonMatch"}>
vless://...#HW-TEST-server

Added via happ://add/http://127.0.0.1:8899/sub. Here is %LOCALAPPDATA%\Happ\routing.json right after the import, trimmed to the interesting fields:

{
  "routings": [
    { "name": "HW-TEST-A", "subscriptionId": 1492684291, "globalProxy": true,  "domainStrategy": "AsIs" },
    { "name": "HW-TEST-B", "subscriptionId": 1492684291, "globalProxy": false, "domainStrategy": "IPIfNonMatch" }
  ],
  "subConfigs": [
    { "subscriptionId": 1492684291, "enabled": true, "ignoreProfile": false,
      "selectedProfile": "HW-TEST-A", "providerRoutingDisabled": false }
  ]
}

Both survived as distinct objects, both pinned to the same subscription id, and the values that differed between them (globalProxy, domainStrategy) came through per profile rather than one overwriting the other. Each also got its own asset directory on disk.

Note selectedProfile: it is a single string, not a list. One profile is active per subscription at any moment and the user switches between them, which is what phase 2 was after. The subscription log says Subscription #1492684291 added successfully: 1 server configs added, so the routing lines are consumed as routing and do not leak into the server list.

This is Happ only. I have no way to test Incy, so that half is still open.

Two things came out of the run that I did not expect.

Routing on the client is already per subscription

Happ 4.x moved it there (dev-docs/routing, "Decentralised architecture"): every subscription owns its own isolated profile set with an independent lifecycle, and removing the subscription cascade-deletes the profiles and their cached geofiles. The old global fields still exist in the file but stayed empty for the whole run ("activeRoutingName": "", "routingNames": []), so they look like v1 leftovers.

Which means the panel is now the only side of this pipe that is still global-only. That is worth knowing before deciding scope on this and #5824.

Profiles cost about 27 MB each and are not deduplicated

Both of my profiles carried the same default Loyalsoldier URLs. Happ downloaded the files twice anyway, once per profile:

routing\1492684291\HW-TEST-A\geoip.dat    16.39 MB
routing\1492684291\HW-TEST-A\geosite.dat  10.48 MB
routing\1492684291\HW-TEST-B\geoip.dat    16.39 MB
routing\1492684291\HW-TEST-B\geosite.dat  10.48 MB
                                    total 53.74 MB

There is no shared cache keyed by URL, the path is routing\<subId>\<profileName>\. So emitting N profiles for one subscription costs the user N x ~27 MB on every device. The de-dup by name in the raw proposal is not just tidiness then, and it is probably worth capping how many profiles one entry may resolve to.

One correction on the JSON side

Happ's docs put JSON subscriptions in a restricted mode: strictly 0 or 1 routing profile, no manual creation, no copying, no clipboard import, master toggle force-locked. I first read that as killing the JSON half of the proposal, but it does not. That rule is about Happ's own profile object. The routing section inside each JSON element is a different thing and still reaches the core, because Happ hands JSON configs to Xray unchanged ("standard HAPP routing rules and interface settings are not applied to the JSON file", dev-docs/examples-of-links-and-parameters section 3.1). So a per-entry routing produced by the deep copy is honoured.

There is a sharp edge though. With useChunkFiles on, Happ trims the geofiles by the tags declared in the routing profile, not by the tags used in the JSON config, and the docs warn about keeping the two in sync. A per-entry routing referencing geosite: or geoip: categories that the single allowed profile does not declare can end up reading a geofile with exactly those sections cut out. So the JSON half works, but a per-entry rule set is only as good as the one profile the subscription is allowed to carry.

<!-- gh-comment-id:5425530802 --> @den41apple commented on GitHub (Aug 26, 2026): I went and tested it. Short answer: yes, Happ keeps them as separate profiles. Setup was Happ Desktop 4.1.1 (602) on Windows, pointed at a local http server returning a plain text body: ``` happ://routing/add/<base64 of {"Name":"HW-TEST-A", ..., "DomainStrategy":"AsIs"}> happ://routing/add/<base64 of {"Name":"HW-TEST-B", ..., "DomainStrategy":"IPIfNonMatch"}> vless://...#HW-TEST-server ``` Added via `happ://add/http://127.0.0.1:8899/sub`. Here is `%LOCALAPPDATA%\Happ\routing.json` right after the import, trimmed to the interesting fields: ```json { "routings": [ { "name": "HW-TEST-A", "subscriptionId": 1492684291, "globalProxy": true, "domainStrategy": "AsIs" }, { "name": "HW-TEST-B", "subscriptionId": 1492684291, "globalProxy": false, "domainStrategy": "IPIfNonMatch" } ], "subConfigs": [ { "subscriptionId": 1492684291, "enabled": true, "ignoreProfile": false, "selectedProfile": "HW-TEST-A", "providerRoutingDisabled": false } ] } ``` Both survived as distinct objects, both pinned to the same subscription id, and the values that differed between them (`globalProxy`, `domainStrategy`) came through per profile rather than one overwriting the other. Each also got its own asset directory on disk. Note `selectedProfile`: it is a single string, not a list. One profile is active per subscription at any moment and the user switches between them, which is what phase 2 was after. The subscription log says `Subscription #1492684291 added successfully: 1 server configs added`, so the routing lines are consumed as routing and do not leak into the server list. This is Happ only. I have no way to test Incy, so that half is still open. Two things came out of the run that I did not expect. ## Routing on the client is already per subscription Happ 4.x moved it there (dev-docs/routing, "Decentralised architecture"): every subscription owns its own isolated profile set with an independent lifecycle, and removing the subscription cascade-deletes the profiles and their cached geofiles. The old global fields still exist in the file but stayed empty for the whole run (`"activeRoutingName": ""`, `"routingNames": []`), so they look like v1 leftovers. Which means the panel is now the only side of this pipe that is still global-only. That is worth knowing before deciding scope on this and #5824. ## Profiles cost about 27 MB each and are not deduplicated Both of my profiles carried the same default Loyalsoldier URLs. Happ downloaded the files twice anyway, once per profile: ``` routing\1492684291\HW-TEST-A\geoip.dat 16.39 MB routing\1492684291\HW-TEST-A\geosite.dat 10.48 MB routing\1492684291\HW-TEST-B\geoip.dat 16.39 MB routing\1492684291\HW-TEST-B\geosite.dat 10.48 MB total 53.74 MB ``` There is no shared cache keyed by URL, the path is `routing\<subId>\<profileName>\`. So emitting N profiles for one subscription costs the user N x ~27 MB on every device. The de-dup by name in the raw proposal is not just tidiness then, and it is probably worth capping how many profiles one entry may resolve to. ## One correction on the JSON side Happ's docs put JSON subscriptions in a restricted mode: strictly 0 or 1 routing profile, no manual creation, no copying, no clipboard import, master toggle force-locked. I first read that as killing the JSON half of the proposal, but it does not. That rule is about Happ's own profile object. The `routing` section inside each JSON element is a different thing and still reaches the core, because Happ hands JSON configs to Xray unchanged ("standard HAPP routing rules and interface settings are not applied to the JSON file", dev-docs/examples-of-links-and-parameters section 3.1). So a per-entry `routing` produced by the deep copy is honoured. There is a sharp edge though. With `useChunkFiles` on, Happ trims the geofiles by the tags declared in the routing profile, not by the tags used in the JSON config, and the docs warn about keeping the two in sync. A per-entry `routing` referencing `geosite:` or `geoip:` categories that the single allowed profile does not declare can end up reading a geofile with exactly those sections cut out. So the JSON half works, but a per-entry rule set is only as good as the one profile the subscription is allowed to carry.
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#4296
No description provided.