[PR #6488] [MERGED] feat(sub): refine Happ routing presets, serverDescription escaping, and auto-detect placement #6302

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6488
Author: @Pejman-Yousefi-Official
Created: 9/12/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei

Base: main ← Head: fix/happ-refinements


📝 Commits (2)

  • 176d542 feat(sub): refine Happ routing presets, serverDescription escaping, and auto-detect placement
  • 888c9e8 fix(sub): address PR review findings on routing parity, agent regex, and i18n

📊 Changes

10 files changed (+307 additions, -167 deletions)

View changed files

📝 frontend/src/pages/settings/HappSettingsContent.tsx (+61 -65)
📝 frontend/src/pages/settings/happPresets.ts (+36 -60)
📝 frontend/src/test/happ-presets.test.ts (+12 -22)
📝 frontend/src/test/happ-settings-tun-mode.test.tsx (+21 -0)
📝 internal/sub/endpoint.go (+23 -5)
📝 internal/sub/endpoint_test.go (+4 -4)
📝 internal/sub/happ.go (+11 -8)
📝 internal/sub/happ_test.go (+124 -1)
📝 internal/sub/host_sub.go (+3 -0)
📝 internal/sub/service.go (+12 -2)

📄 Description

Summary

Follow-up refinements to the Happ client integration (#6434) ensuring strict conformance with official Happ developer specifications, robust fragment parameter escaping, synchronized routing off-state headers, and enhanced UI discoverability.

Why

  1. Native Happ routing profile shape:
    • Happ's happ://routing/onadd/<base64> deeplink requires a vendor profile JSON object (Name, GlobalProxy, DirectSites, DirectIp, BlockSites, BlockIp, etc.) rather than Xray core field rules. Both the visual rule generator and curated presets (Iran Bypass, China Direct, AdBlock, Global) now generate standard Happ profile payloads.
  2. Precise server description escaping with strings.Cut:
    • The subtitle parameter separation in appendQueryAndFragment now explicitly targets ?serverDescription= via strings.Cut. This prevents unescaping literal ? characters in node remarks (e.g. Server? 01) while cleanly preserving the base64-encoded Happ subtitle query.
  3. Guaranteed off-state deeplink parity:
    • When happ://routing/off is configured, Routing-Enable: 0 and Routing: happ://routing/off are guaranteed to emit in lockstep even if general routing was previously toggled on, allowing Happ clients to clear cached rules reliably.
  4. Master toggle discoverability & UX polish:
    • Promoted subHappAutoDetect to the top of the Happ settings tab as a prominent master switch, preventing operator confusion where Happ headers were gated off.
    • Added quick theme presets (resetcolors, Dark Violet, Turquoise) in the Themes tab with standard t('reset') localization.
    • Normalized the preset button label to t('apply').

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  • Go unit tests:
    • go test -v ./internal/sub/... (all tests pass).
    • Verified TestApplyCommonHeaders_HappRoutingOffDeeplink enforces Routing-Enable: 0 on off deeplinks.
    • Verified TestAppendQueryAndFragment_PreservesServerDescription covers literal ? remarks and encoded subtitle parameters.
  • Frontend unit tests:
    • npx vitest run src/test/happ-presets.test.ts src/test/happ-settings-tun-mode.test.tsx (10/10 tests pass).
    • Verified preset payloads match native Happ profile JSON schemas.
    • Verified the Auto-Detection master switch renders at the top and updates settings properly.
  • Code standards & formatting:
    • npm run lint (oxlint): 0 errors, 0 warnings across 540 files.
    • npm run typecheck (tsc --noEmit): clean, 0 errors.
    • go build ./... and go vet ./...: clean exit 0.

Breaking changes

None. All changes are strictly additive and backward compatible.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/6488 **Author:** [@Pejman-Yousefi-Official](https://github.com/Pejman-Yousefi-Official) **Created:** 9/12/2026 **Status:** ✅ Merged **Merged:** 9/13/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/happ-refinements` --- ### 📝 Commits (2) - [`176d542`](https://github.com/MHSanaei/3x-ui/commit/176d542c0b9ed309d722aa27259c4453a14e7c6c) feat(sub): refine Happ routing presets, serverDescription escaping, and auto-detect placement - [`888c9e8`](https://github.com/MHSanaei/3x-ui/commit/888c9e8ff2f0db70dc27969ad7d4d2d0c10c0863) fix(sub): address PR review findings on routing parity, agent regex, and i18n ### 📊 Changes **10 files changed** (+307 additions, -167 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/settings/HappSettingsContent.tsx` (+61 -65) 📝 `frontend/src/pages/settings/happPresets.ts` (+36 -60) 📝 `frontend/src/test/happ-presets.test.ts` (+12 -22) 📝 `frontend/src/test/happ-settings-tun-mode.test.tsx` (+21 -0) 📝 `internal/sub/endpoint.go` (+23 -5) 📝 `internal/sub/endpoint_test.go` (+4 -4) 📝 `internal/sub/happ.go` (+11 -8) 📝 `internal/sub/happ_test.go` (+124 -1) 📝 `internal/sub/host_sub.go` (+3 -0) 📝 `internal/sub/service.go` (+12 -2) </details> ### 📄 Description ## Summary Follow-up refinements to the Happ client integration (#6434) ensuring strict conformance with official Happ developer specifications, robust fragment parameter escaping, synchronized routing off-state headers, and enhanced UI discoverability. ## Why 1. **Native Happ routing profile shape:** - Happ's `happ://routing/onadd/<base64>` deeplink requires a vendor profile JSON object (`Name`, `GlobalProxy`, `DirectSites`, `DirectIp`, `BlockSites`, `BlockIp`, etc.) rather than Xray core field rules. Both the visual rule generator and curated presets (Iran Bypass, China Direct, AdBlock, Global) now generate standard Happ profile payloads. 2. **Precise server description escaping with `strings.Cut`:** - The subtitle parameter separation in `appendQueryAndFragment` now explicitly targets `?serverDescription=` via `strings.Cut`. This prevents unescaping literal `?` characters in node remarks (e.g. `Server? 01`) while cleanly preserving the base64-encoded Happ subtitle query. 3. **Guaranteed off-state deeplink parity:** - When `happ://routing/off` is configured, `Routing-Enable: 0` and `Routing: happ://routing/off` are guaranteed to emit in lockstep even if general routing was previously toggled on, allowing Happ clients to clear cached rules reliably. 4. **Master toggle discoverability & UX polish:** - Promoted `subHappAutoDetect` to the top of the Happ settings tab as a prominent master switch, preventing operator confusion where Happ headers were gated off. - Added quick theme presets (`resetcolors`, Dark Violet, Turquoise) in the Themes tab with standard `t('reset')` localization. - Normalized the preset button label to `t('apply')`. ## Type of change - [x] Bug fix - [x] New feature - [x] Refactoring (no behavior change) - [ ] Documentation - [x] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - **Go unit tests:** - `go test -v ./internal/sub/...` (all tests pass). - Verified `TestApplyCommonHeaders_HappRoutingOffDeeplink` enforces `Routing-Enable: 0` on off deeplinks. - Verified `TestAppendQueryAndFragment_PreservesServerDescription` covers literal `?` remarks and encoded subtitle parameters. - **Frontend unit tests:** - `npx vitest run src/test/happ-presets.test.ts src/test/happ-settings-tun-mode.test.tsx` (10/10 tests pass). - Verified preset payloads match native Happ profile JSON schemas. - Verified the Auto-Detection master switch renders at the top and updates settings properly. - **Code standards & formatting:** - `npm run lint` (`oxlint`): 0 errors, 0 warnings across 540 files. - `npm run typecheck` (`tsc --noEmit`): clean, 0 errors. - `go build ./...` and `go vet ./...`: clean exit 0. ## Breaking changes None. All changes are strictly additive and backward compatible. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <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:48 +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#6302
No description provided.