mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5672] [CLOSED] feat(sub): auto-detect subscription format by User-Agent #5953
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#5953
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/5672
Author: @Tomilla
Created: 6/30/2026
Status: ❌ Closed
Base:
main← Head:feat_auto_detect_sub_url📝 Commits (10+)
fe4bd4afeat(settings): expose JSON and Clash subscription URLse4f2aadfeat(sub): auto-detect Clash and Mihomo clients2b650ecrefactor(settings): group subscription format endpoints61bdbaefeat(sub): auto-detect Xray JSON clientscfed712fix(settings): validate regexes with Go RE2a0d32ecfeat(sub): make JSON array responses configurable8b174b3fix(settings): preserve inherited regex defaults59e75a5refactor(settings): clarify subscription format controlsb05a5b0fix(xray): validate balancer regexes on submitd4e9b98refactor(sub): rename Clash auto-detect setting📊 Changes
41 files changed (+1771 additions, -107 deletions)
View changed files
📝
frontend/public/openapi.json(+97 -0)➕
frontend/src/components/form/GoRegexInput.tsx(+63 -0)📝
frontend/src/components/form/index.ts(+1 -0)📝
frontend/src/generated/examples.ts(+10 -0)📝
frontend/src/generated/schemas.ts(+50 -0)📝
frontend/src/generated/types.ts(+10 -0)📝
frontend/src/generated/zod.ts(+10 -0)📝
frontend/src/models/setting.ts(+5 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+9 -2)📝
frontend/src/pages/settings/SubscriptionFormatsTab.css(+15 -0)📝
frontend/src/pages/settings/SubscriptionFormatsTab.tsx(+70 -6)📝
frontend/src/pages/settings/SubscriptionGeneralTab.tsx(+17 -1)📝
frontend/src/pages/xray/balancers/BalancerFormModal.tsx(+71 -10)📝
frontend/src/schemas/setting.ts(+5 -0)📝
frontend/src/test/balancer-form-modal.test.tsx(+101 -5)➕
frontend/src/test/subscription-general-tab.test.tsx(+29 -0)📝
internal/sub/controller.go(+277 -57)📝
internal/sub/controller_test.go(+318 -0)📝
internal/sub/external_only_sub_test.go(+19 -1)📝
internal/sub/host_sub_test.go(+2 -2)...and 21 more files
📄 Description
Summary
Adds optional User-Agent detection to serve Clash/Mihomo YAML or Xray JSON from the standard subscription URL.
Also exposes JSON and Clash/Mihomo endpoint paths, reverse proxy URLs, auto-detection settings, and configurable Go RE2 User-Agent patterns in the panel.
Why
Currently, raw, JSON, and Clash subscriptions use separate URLs. This is inconvenient for administrators and users migrating from panels that expose one subscription URL and select the response format based on the requesting client.
This change keeps all existing endpoints available while optionally allowing the standard subscription URL to return the appropriate format.
Auto-detection is disabled by default to preserve existing behavior.
Closes #5570
Type of change
Areas affected
How was this tested?
Automated checks:
go build ./...go test ./...npm run typechecknpm run lintnpm run test— 637 tests passednpm run buildManual subscription checks:
Screenshots / recordings
Screenshots to attach:
Subscription tab showing the link to format-specific settings.

Sub Formats tab showing separate JSON and Clash/Mihomo sections.

User-Agent auto-detection and regex settings.

Invalid Go RE2 validation error.


User Agent Regex field:
Balance Cost Regex field:
Breaking changes
None.
Existing subscription URLs and response behavior remain unchanged unless an administrator explicitly enables auto-detection.
The existing JSON and Clash/Mihomo endpoints remain available.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.