fix: allow disabling ALPN by setting an empty array (#2225)

This commit is contained in:
eWloYW8 2025-08-24 13:16:30 +08:00 committed by wwqgtxx
parent e3d9a8e2fd
commit d2395fb43a
3 changed files with 4 additions and 4 deletions

View File

@ -172,7 +172,7 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
return nil, err 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 tlsConfig.NextProtos = option.ALPN
} else { } else {
tlsConfig.NextProtos = []string{DefaultALPN} tlsConfig.NextProtos = []string{DefaultALPN}

View File

@ -153,7 +153,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
return nil, err 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 tlsConfig.NextProtos = option.ALPN
} }

View File

@ -95,7 +95,7 @@ func (t *Trojan) StreamConnContext(ctx context.Context, c net.Conn, metadata *C.
} }
alpn := trojan.DefaultWebsocketALPN 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 alpn = t.option.ALPN
} }
@ -119,7 +119,7 @@ func (t *Trojan) StreamConnContext(ctx context.Context, c net.Conn, metadata *C.
// default tcp network // default tcp network
// handle TLS // handle TLS
alpn := trojan.DefaultALPN 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 alpn = t.option.ALPN
} }
c, err = vmess.StreamTLSConn(ctx, c, &vmess.TLSConfig{ c, err = vmess.StreamTLSConn(ctx, c, &vmess.TLSConfig{