Skip to content

Commit d2395fb

Browse files
eWloYW8wwqgtxx
authored andcommitted
fix: allow disabling ALPN by setting an empty array (#2225)
1 parent e3d9a8e commit d2395fb

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

adapter/outbound/hysteria.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
172172
return nil, err
173173
}
174174

175-
if len(option.ALPN) > 0 {
175+
if option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array
176176
tlsConfig.NextProtos = option.ALPN
177177
} else {
178178
tlsConfig.NextProtos = []string{DefaultALPN}

adapter/outbound/hysteria2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
153153
return nil, err
154154
}
155155

156-
if len(option.ALPN) > 0 {
156+
if option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array
157157
tlsConfig.NextProtos = option.ALPN
158158
}
159159

adapter/outbound/trojan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (t *Trojan) StreamConnContext(ctx context.Context, c net.Conn, metadata *C.
9595
}
9696

9797
alpn := trojan.DefaultWebsocketALPN
98-
if len(t.option.ALPN) != 0 {
98+
if t.option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array
9999
alpn = t.option.ALPN
100100
}
101101

@@ -119,7 +119,7 @@ func (t *Trojan) StreamConnContext(ctx context.Context, c net.Conn, metadata *C.
119119
// default tcp network
120120
// handle TLS
121121
alpn := trojan.DefaultALPN
122-
if len(t.option.ALPN) != 0 {
122+
if t.option.ALPN != nil { // structure's Decode will ensure value not nil when input has value even it was set an empty array
123123
alpn = t.option.ALPN
124124
}
125125
c, err = vmess.StreamTLSConn(ctx, c, &vmess.TLSConfig{

0 commit comments

Comments
 (0)