From 8add78c02bce2305d3131d2cfdde1d8b7eeb7853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=90=B2=93=F0=90=B3=9B=F0=90=B3=AA=F0=90=B3=82?= =?UTF-8?q?=F0=90=B3=90=20=F0=90=B2=80=F0=90=B3=A2=F0=90=B3=A6=F0=90=B3=AB?= =?UTF-8?q?=F0=90=B3=A2=20=F0=90=B2=A5=F0=90=B3=94=F0=90=B3=9B=F0=90=B3=AA?= =?UTF-8?q?=F0=90=B3=8C=F0=90=B3=91=F0=90=B3=96=F0=90=B3=87?= <26771058+KobeArthurScofield@users.noreply.github.com> Date: Sat, 13 Sep 2025 20:11:24 +0800 Subject: [PATCH] Fix https://github.com/XTLS/Xray-core/pull/5124#pullrequestreview-3218097421 --- infra/conf/http.go | 21 +++++++++++++++------ infra/conf/socks.go | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/infra/conf/http.go b/infra/conf/http.go index d4092f88..84155d54 100644 --- a/infra/conf/http.go +++ b/infra/conf/http.go @@ -64,12 +64,21 @@ type HTTPClientConfig struct { func (v *HTTPClientConfig) Build() (proto.Message, error) { config := new(http.ClientConfig) if v.Address != nil { - v.Servers = []*HTTPRemoteConfig{ - { - Address: v.Address, - Port: v.Port, - Users: []json.RawMessage{{}}, - }, + if len(v.Username) == 0 { + v.Servers = []*HTTPRemoteConfig{ + { + Address: v.Address, + Port: v.Port, + }, + } + } else { + v.Servers = []*HTTPRemoteConfig{ + { + Address: v.Address, + Port: v.Port, + Users: []json.RawMessage{{}}, + }, + } } } config.Server = make([]*protocol.ServerEndpoint, len(v.Servers)) diff --git a/infra/conf/socks.go b/infra/conf/socks.go index 6955001f..1d7c6249 100644 --- a/infra/conf/socks.go +++ b/infra/conf/socks.go @@ -82,12 +82,21 @@ type SocksClientConfig struct { func (v *SocksClientConfig) Build() (proto.Message, error) { config := new(socks.ClientConfig) if v.Address != nil { - v.Servers = []*SocksRemoteConfig{ - { - Address: v.Address, - Port: v.Port, - Users: []json.RawMessage{{}}, - }, + if len(v.Username) == 0 { + v.Servers = []*SocksRemoteConfig{ + { + Address: v.Address, + Port: v.Port, + }, + } + } else { + v.Servers = []*SocksRemoteConfig{ + { + Address: v.Address, + Port: v.Port, + Users: []json.RawMessage{{}}, + }, + } } } config.Server = make([]*protocol.ServerEndpoint, len(v.Servers))