mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5417] [MERGED] feat(sub): full XHTTP field mapping for Clash/Mihomo subscriptions #5878
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#5878
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/5417
Author: @w3struk
Created: 6/17/2026
Status: ✅ Merged
Merged: 6/20/2026
Merged by: @MHSanaei
Base:
main← Head:fix/clash-xhttp-opts-clean📝 Commits (6)
23e7367feat(sub): add full XHTTP field mapping for Clash subscriptions1800026test(sub): add comprehensive tests for buildXhttpClashOpts1af0903Merge branch 'main' into fix/clash-xhttp-opts-cleanec402a5Merge branch 'main' into fix/clash-xhttp-opts-cleancd9f1f8Merge branch 'main' into fix/clash-xhttp-opts-clean54f0f61fix(sub): clean up redundant skipValue check and add missing xhttp no-settings test📊 Changes
2 files changed (+594 additions, -19 deletions)
View changed files
📝
internal/sub/clash_service.go(+124 -19)📝
internal/sub/clash_service_test.go(+470 -0)📄 Description
Summary
The Clash subscription generator (
clash_service.go) only emittedpath,host,modeinxhttp-opts. Mihomo supports ALL XHTTP parameters including padding, xmux (asreuse-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.gobuildXhttpClashOpts()(lines 363-473): ConvertsxhttpSettingsmap to Mihomo-compatiblexhttp-optsmapscMaxEachPostBytes="1000000",scMinPostsIntervalMs="30")noGRPCHeader,xPaddingObfsModexPaddingObfsMode=truexmux→reuse-settingswith kebab-case sub-field mappingnilfor empty opts (consistent withbuildXhttpExtra)applyTransportxhttp case (lines 547-554): Delegates tobuildXhttpClashOptsinternal/sub/clash_service_test.goTestBuildXhttpClashOpts_FullFieldMapping— every kebab-case key verifiedTestBuildXhttpClashOpts_DPIDefaultsFiltered— DPI fingerprint defaults filteredTestBuildXhttpClashOpts_PaddingObfsGate— false/absent/true-with-no-gated-fieldsTestBuildXhttpClashOpts_XmuxMapsToReuseSettings— full mapping, empty, int/float64/zero hKeepAlivePeriodTestBuildXhttpClashOpts_ServerOnlyFieldsExcluded— noSSEHeader, scMaxBufferedPosts, etc.TestBuildXhttpClashOpts_NilInput/_EmptyInput— return nilTestBuildXhttpClashOpts_HostFallbackFromHeaders— headers.Host, only-Host, case-insensitive dropTestBuildXhttpClashOpts_NoGRPCHeaderFalsey— false and absent both produce no keyField Mapping (source-verified against Mihomo
adapter/outbound/vless.go)pathpathhosthostmodemodeheadersheadersnoGRPCHeaderno-grpc-headerxPaddingBytesx-padding-bytesxPaddingObfsModex-padding-obfs-modexPaddingKeyx-padding-keyxPaddingHeaderx-padding-headerxPaddingPlacementx-padding-placementxPaddingMethodx-padding-methoduplinkHTTPMethoduplink-http-methodsessionPlacementsession-placementsessionKeysession-keyseqPlacementseq-placementseqKeyseq-keyuplinkDataPlacementuplink-data-placementuplinkDataKeyuplink-data-keyuplinkChunkSizeuplink-chunk-sizescMaxEachPostBytessc-max-each-post-bytesscMinPostsIntervalMssc-min-posts-interval-msxmuxreuse-settingsXMUX → 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,serverMaxHeaderBytesDeferred to follow-up PR
downloadSettings→download-settings(complex nested structure)Testing
TestApplyTransport_XHTTPandTestApplyTransport_XHTTP_HostFromHeadersstill passRelated
adapter/outbound/vless.gostruct tags)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.