[PR #5416] [CLOSED] feat(sub): full XHTTP field mapping for Clash/Mihomo subscriptions #5876

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5416
Author: @w3struk
Created: 6/17/2026
Status: ❌ Closed

Base: main ← Head: fix/clash-xhttp-opts


📝 Commits (6)

  • 5ddb05a fix(sub): preserve non-default scMinPostsIntervalMs in inbound wire payload
  • 4a31f92 fix(sub): use per-inbound xmux instead of global subJsonMux in JSON subscriptions
  • d1fd93e feat(ui): add scMinPostsIntervalMs to inbound XHTTP form
  • 2ae9eff fix(ui): show packet-up fields for auto mode in inbound XHTTP form
  • bf7c4c3 feat(sub): add full XHTTP field mapping for Clash subscriptions
  • 321549c test(sub): add comprehensive tests for buildXhttpClashOpts

📊 Changes

9 files changed (+832 additions, -50 deletions)

View changed files

📝 frontend/src/lib/xray/stream-wire-normalize.ts (+6 -1)
📝 frontend/src/pages/inbounds/form/transport/xhttp.tsx (+7 -1)
📝 frontend/src/schemas/protocols/stream/xhttp.ts (+6 -3)
📝 frontend/src/test/stream-wire-normalize.test.ts (+118 -0)
📝 internal/sub/clash_service.go (+124 -19)
📝 internal/sub/clash_service_test.go (+454 -0)
📝 internal/sub/json_service.go (+26 -16)
📝 internal/sub/json_service_test.go (+85 -4)
📝 internal/sub/mutation_audit_test.go (+6 -6)

📄 Description

Summary

The Clash subscription generator (clash_service.go) only emitted path, host, mode in xhttp-opts. Mihomo supports ALL XHTTP parameters including padding, xmux (as reuse-settings), session/seq placement, and more.

This PR adds buildXhttpClashOpts() — an allowlist-based function that maps all client-relevant XHTTP fields from 3x-ui's camelCase JSON storage to Mihomo's kebab-case YAML format.

Changes

internal/sub/clash_service.go

  • New function buildXhttpClashOpts() (lines 363-473): Converts xhttpSettings map to Mihomo-compatible xhttp-opts map
    • String field mapping with DPI default filtering (scMaxEachPostBytes="1000000", scMinPostsIntervalMs="30")
    • Bool fields (truthy only): noGRPCHeader, xPaddingObfsMode
    • Padding obfs gated fields: only emitted when xPaddingObfsMode=true
    • Nested xmux → reuse-settings with kebab-case sub-field mapping
    • Headers with case-insensitive Host key drop
    • Returns nil for empty opts (consistent with buildXhttpExtra)
  • Updated applyTransport xhttp case (lines 547-554): Delegates to buildXhttpClashOpts

internal/sub/clash_service_test.go

  • 9 new test functions (454 lines) covering:
    • TestBuildXhttpClashOpts_FullFieldMapping — every kebab-case key verified
    • TestBuildXhttpClashOpts_DPIDefaultsFiltered — DPI fingerprint defaults filtered
    • TestBuildXhttpClashOpts_PaddingObfsGate — false/absent/true-with-no-gated-fields
    • TestBuildXhttpClashOpts_XmuxMapsToReuseSettings — full mapping, empty, int/float64/zero hKeepAlivePeriod
    • TestBuildXhttpClashOpts_ServerOnlyFieldsExcluded — noSSEHeader, scMaxBufferedPosts, etc.
    • TestBuildXhttpClashOpts_NilInput / _EmptyInput — return nil
    • TestBuildXhttpClashOpts_HostFallbackFromHeaders — headers.Host, only-Host, case-insensitive drop
    • TestBuildXhttpClashOpts_NoGRPCHeaderFalsey — false and absent both produce no key

Field Mapping (source-verified against Mihomo adapter/outbound/vless.go)

3x-ui (camelCase) Mihomo (kebab-case) Type Filter
path path string direct
host host string direct + headers fallback
mode mode string direct
headers headers map drop Host key
noGRPCHeader no-grpc-header bool truthy only
xPaddingBytes x-padding-bytes string non-empty
xPaddingObfsMode x-padding-obfs-mode bool truthy only
xPaddingKey x-padding-key string non-empty, gated by obfs mode
xPaddingHeader x-padding-header string non-empty, gated by obfs mode
xPaddingPlacement x-padding-placement string non-empty, gated by obfs mode
xPaddingMethod x-padding-method string non-empty, gated by obfs mode
uplinkHTTPMethod uplink-http-method string non-empty
sessionPlacement session-placement string non-empty
sessionKey session-key string non-empty
seqPlacement seq-placement string non-empty
seqKey seq-key string non-empty
uplinkDataPlacement uplink-data-placement string non-empty
uplinkDataKey uplink-data-key string non-empty
uplinkChunkSize uplink-chunk-size string non-zero
scMaxEachPostBytes sc-max-each-post-bytes string non-empty, filter "1000000"
scMinPostsIntervalMs sc-min-posts-interval-ms string non-empty, filter "30"
xmux reuse-settings nested non-empty object

XMUX → reuse-settings sub-fields

| maxConcurrency | max-concurrency | string | non-empty |
| maxConnections | max-connections | string | non-empty |
| cMaxReuseTimes | c-max-reuse-times | string | non-empty |
| hMaxRequestTimes | h-max-request-times | string | non-empty |
| hMaxReusableSecs | h-max-reusable-secs | string | non-empty |
| hKeepAlivePeriod | h-keep-alive-period | int | non-zero |

Server-only fields (EXCLUDED — not in allowlist)

  • noSSEHeader, scMaxBufferedPosts, scStreamUpServerSecs, serverMaxHeaderBytes

Deferred to follow-up PR

  • downloadSettings → download-settings (complex nested structure)

Testing

  • All 15 test cases pass (9 functions with sub-tests)
  • Existing TestApplyTransport_XHTTP and TestApplyTransport_XHTTP_HostFromHeaders still pass
  • Tested locally with Mihomo v1.19.27 — connection successful, all XHTTP fields accepted
  • Builds on #5393 (JSON subscription XHTTP client fields fix)
  • Mihomo XHTTP field names verified against source code (adapter/outbound/vless.go struct tags)

🔄 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/5416 **Author:** [@w3struk](https://github.com/w3struk) **Created:** 6/17/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/clash-xhttp-opts` --- ### 📝 Commits (6) - [`5ddb05a`](https://github.com/MHSanaei/3x-ui/commit/5ddb05ae50f165fc67367af7c943bc448cc24950) fix(sub): preserve non-default scMinPostsIntervalMs in inbound wire payload - [`4a31f92`](https://github.com/MHSanaei/3x-ui/commit/4a31f92a0847c04a94f8030caa677bb8d1dd80dc) fix(sub): use per-inbound xmux instead of global subJsonMux in JSON subscriptions - [`d1fd93e`](https://github.com/MHSanaei/3x-ui/commit/d1fd93efa0938e720d4628e685c7db0318edf612) feat(ui): add scMinPostsIntervalMs to inbound XHTTP form - [`2ae9eff`](https://github.com/MHSanaei/3x-ui/commit/2ae9effd2136c7189b3217612821a5ad08ba4d74) fix(ui): show packet-up fields for auto mode in inbound XHTTP form - [`bf7c4c3`](https://github.com/MHSanaei/3x-ui/commit/bf7c4c39fba58e932dcfc432558b82c534c570f2) feat(sub): add full XHTTP field mapping for Clash subscriptions - [`321549c`](https://github.com/MHSanaei/3x-ui/commit/321549c2d22fed86269043ff2adab23bb3c59fe7) test(sub): add comprehensive tests for buildXhttpClashOpts ### 📊 Changes **9 files changed** (+832 additions, -50 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/lib/xray/stream-wire-normalize.ts` (+6 -1) 📝 `frontend/src/pages/inbounds/form/transport/xhttp.tsx` (+7 -1) 📝 `frontend/src/schemas/protocols/stream/xhttp.ts` (+6 -3) 📝 `frontend/src/test/stream-wire-normalize.test.ts` (+118 -0) 📝 `internal/sub/clash_service.go` (+124 -19) 📝 `internal/sub/clash_service_test.go` (+454 -0) 📝 `internal/sub/json_service.go` (+26 -16) 📝 `internal/sub/json_service_test.go` (+85 -4) 📝 `internal/sub/mutation_audit_test.go` (+6 -6) </details> ### 📄 Description ## Summary The Clash subscription generator (`clash_service.go`) only emitted `path`, `host`, `mode` in `xhttp-opts`. Mihomo supports ALL XHTTP parameters including padding, xmux (as `reuse-settings`), session/seq placement, and more. This PR adds `buildXhttpClashOpts()` — an allowlist-based function that maps all client-relevant XHTTP fields from 3x-ui's camelCase JSON storage to Mihomo's kebab-case YAML format. ## Changes ### `internal/sub/clash_service.go` - **New function `buildXhttpClashOpts()`** (lines 363-473): Converts `xhttpSettings` map to Mihomo-compatible `xhttp-opts` map - String field mapping with DPI default filtering (`scMaxEachPostBytes="1000000"`, `scMinPostsIntervalMs="30"`) - Bool fields (truthy only): `noGRPCHeader`, `xPaddingObfsMode` - Padding obfs gated fields: only emitted when `xPaddingObfsMode=true` - Nested `xmux` → `reuse-settings` with kebab-case sub-field mapping - Headers with case-insensitive Host key drop - Returns `nil` for empty opts (consistent with `buildXhttpExtra`) - **Updated `applyTransport` xhttp case** (lines 547-554): Delegates to `buildXhttpClashOpts` ### `internal/sub/clash_service_test.go` - **9 new test functions** (454 lines) covering: - `TestBuildXhttpClashOpts_FullFieldMapping` — every kebab-case key verified - `TestBuildXhttpClashOpts_DPIDefaultsFiltered` — DPI fingerprint defaults filtered - `TestBuildXhttpClashOpts_PaddingObfsGate` — false/absent/true-with-no-gated-fields - `TestBuildXhttpClashOpts_XmuxMapsToReuseSettings` — full mapping, empty, int/float64/zero hKeepAlivePeriod - `TestBuildXhttpClashOpts_ServerOnlyFieldsExcluded` — noSSEHeader, scMaxBufferedPosts, etc. - `TestBuildXhttpClashOpts_NilInput` / `_EmptyInput` — return nil - `TestBuildXhttpClashOpts_HostFallbackFromHeaders` — headers.Host, only-Host, case-insensitive drop - `TestBuildXhttpClashOpts_NoGRPCHeaderFalsey` — false and absent both produce no key ## Field Mapping (source-verified against Mihomo `adapter/outbound/vless.go`) | 3x-ui (camelCase) | Mihomo (kebab-case) | Type | Filter | |---|---|---|---| | `path` | `path` | string | direct | | `host` | `host` | string | direct + headers fallback | | `mode` | `mode` | string | direct | | `headers` | `headers` | map | drop Host key | | `noGRPCHeader` | `no-grpc-header` | bool | truthy only | | `xPaddingBytes` | `x-padding-bytes` | string | non-empty | | `xPaddingObfsMode` | `x-padding-obfs-mode` | bool | truthy only | | `xPaddingKey` | `x-padding-key` | string | non-empty, gated by obfs mode | | `xPaddingHeader` | `x-padding-header` | string | non-empty, gated by obfs mode | | `xPaddingPlacement` | `x-padding-placement` | string | non-empty, gated by obfs mode | | `xPaddingMethod` | `x-padding-method` | string | non-empty, gated by obfs mode | | `uplinkHTTPMethod` | `uplink-http-method` | string | non-empty | | `sessionPlacement` | `session-placement` | string | non-empty | | `sessionKey` | `session-key` | string | non-empty | | `seqPlacement` | `seq-placement` | string | non-empty | | `seqKey` | `seq-key` | string | non-empty | | `uplinkDataPlacement` | `uplink-data-placement` | string | non-empty | | `uplinkDataKey` | `uplink-data-key` | string | non-empty | | `uplinkChunkSize` | `uplink-chunk-size` | string | non-zero | | `scMaxEachPostBytes` | `sc-max-each-post-bytes` | string | non-empty, filter "1000000" | | `scMinPostsIntervalMs` | `sc-min-posts-interval-ms` | string | non-empty, filter "30" | | `xmux` | `reuse-settings` | nested | non-empty object | ### XMUX → reuse-settings sub-fields | `maxConcurrency` | `max-concurrency` | string | non-empty | | `maxConnections` | `max-connections` | string | non-empty | | `cMaxReuseTimes` | `c-max-reuse-times` | string | non-empty | | `hMaxRequestTimes` | `h-max-request-times` | string | non-empty | | `hMaxReusableSecs` | `h-max-reusable-secs` | string | non-empty | | `hKeepAlivePeriod` | `h-keep-alive-period` | int | non-zero | ### Server-only fields (EXCLUDED — not in allowlist) - `noSSEHeader`, `scMaxBufferedPosts`, `scStreamUpServerSecs`, `serverMaxHeaderBytes` ### Deferred to follow-up PR - `downloadSettings` → `download-settings` (complex nested structure) ## Testing - All 15 test cases pass (9 functions with sub-tests) - Existing `TestApplyTransport_XHTTP` and `TestApplyTransport_XHTTP_HostFromHeaders` still pass - Tested locally with Mihomo v1.19.27 — connection successful, all XHTTP fields accepted ## Related - Builds on #5393 (JSON subscription XHTTP client fields fix) - Mihomo XHTTP field names verified against source code (`adapter/outbound/vless.go` struct tags) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:43 +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#5876
No description provided.