From d2395fb43a5f4fcf2146deca2519f45c133f999f Mon Sep 17 00:00:00 2001 From: eWloYW8 <3171132517@qq.com> Date: Sun, 24 Aug 2025 13:16:30 +0800 Subject: [PATCH] fix: allow disabling ALPN by setting an empty array (#2225) --- adapter/outbound/hysteria.go | 2 +- adapter/outbound/hysteria2.go | 2 +- adapter/outbound/trojan.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adapter/outbound/hysteria.go b/adapter/outbound/hysteria.go index 966fa745..38318459 100644 --- a/adapter/outbound/hysteria.go +++ b/adapter/outbound/hysteria.go @@ -172,7 +172,7 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) { return nil, err } - if len(option.ALPN) > 0 { + if option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array tlsConfig.NextProtos = option.ALPN } else { tlsConfig.NextProtos = []string{DefaultALPN} diff --git a/adapter/outbound/hysteria2.go b/adapter/outbound/hysteria2.go index cb844e1f..e7b9f0b5 100644 --- a/adapter/outbound/hysteria2.go +++ b/adapter/outbound/hysteria2.go @@ -153,7 +153,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) { return nil, err } - if len(option.ALPN) > 0 { + if option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array tlsConfig.NextProtos = option.ALPN } diff --git a/adapter/outbound/trojan.go b/adapter/outbound/trojan.go index 9795ed78..f33ac5d6 100644 --- a/adapter/outbound/trojan.go +++ b/adapter/outbound/trojan.go @@ -95,7 +95,7 @@ func (t *Trojan) StreamConnContext(ctx context.Context, c net.Conn, metadata *C. } alpn := trojan.DefaultWebsocketALPN - if len(t.option.ALPN) != 0 { + if t.option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array alpn = t.option.ALPN } @@ -119,7 +119,7 @@ func (t *Trojan) StreamConnContext(ctx context.Context, c net.Conn, metadata *C. // default tcp network // handle TLS alpn := trojan.DefaultALPN - if len(t.option.ALPN) != 0 { + if t.option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array alpn = t.option.ALPN } c, err = vmess.StreamTLSConn(ctx, c, &vmess.TLSConfig{