diff --git a/common/tls/std_server.go b/common/tls/std_server.go index 11c78f48..2c875855 100644 --- a/common/tls/std_server.go +++ b/common/tls/std_server.go @@ -180,7 +180,7 @@ func NewSTDServer(ctx context.Context, router adapter.Router, logger log.Logger, tlsConfig.ServerName = options.ServerName } if len(options.ALPN) > 0 { - tlsConfig.NextProtos = append(tlsConfig.NextProtos, options.ALPN...) + tlsConfig.NextProtos = append(options.ALPN, tlsConfig.NextProtos...) } if options.MinVersion != "" { minVersion, err := ParseTLSVersion(options.MinVersion) diff --git a/transport/v2raygrpc/server.go b/transport/v2raygrpc/server.go index aadc23d2..7073eb08 100644 --- a/transport/v2raygrpc/server.go +++ b/transport/v2raygrpc/server.go @@ -15,6 +15,7 @@ import ( M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" + "golang.org/x/net/http2" "google.golang.org/grpc" "google.golang.org/grpc/keepalive" gM "google.golang.org/grpc/metadata" @@ -32,7 +33,9 @@ type Server struct { func NewServer(ctx context.Context, options option.V2RayGRPCOptions, tlsConfig tls.ServerConfig, handler N.TCPConnectionHandler) (*Server, error) { var serverOptions []grpc.ServerOption if tlsConfig != nil { - tlsConfig.SetNextProtos([]string{"h2"}) + if !common.Contains(tlsConfig.NextProtos(), http2.NextProtoTLS) { + tlsConfig.SetNextProtos(append([]string{"h2"}, tlsConfig.NextProtos()...)) + } serverOptions = append(serverOptions, grpc.Creds(NewTLSTransportCredentials(tlsConfig))) } if options.IdleTimeout > 0 { diff --git a/transport/v2raygrpclite/server.go b/transport/v2raygrpclite/server.go index c3c62232..2d6687fe 100644 --- a/transport/v2raygrpclite/server.go +++ b/transport/v2raygrpclite/server.go @@ -101,8 +101,8 @@ func (s *Server) fallbackRequest(ctx context.Context, writer http.ResponseWriter func (s *Server) Serve(listener net.Listener) error { if s.tlsConfig != nil { - if len(s.tlsConfig.NextProtos()) == 0 { - s.tlsConfig.SetNextProtos([]string{http2.NextProtoTLS}) + if !common.Contains(s.tlsConfig.NextProtos(), http2.NextProtoTLS) { + s.tlsConfig.SetNextProtos(append([]string{"h2"}, s.tlsConfig.NextProtos()...)) } listener = aTLS.NewListener(listener, s.tlsConfig) } diff --git a/transport/v2rayhttp/server.go b/transport/v2rayhttp/server.go index 95588f43..304836ec 100644 --- a/transport/v2rayhttp/server.go +++ b/transport/v2rayhttp/server.go @@ -161,6 +161,11 @@ func (s *Server) fallbackRequest(ctx context.Context, writer http.ResponseWriter func (s *Server) Serve(listener net.Listener) error { if s.tlsConfig != nil { + if len(s.tlsConfig.NextProtos()) == 0 { + s.tlsConfig.SetNextProtos([]string{http2.NextProtoTLS, "http/1.1"}) + } else if !common.Contains(s.tlsConfig.NextProtos(), http2.NextProtoTLS) { + s.tlsConfig.SetNextProtos(append([]string{"h2"}, s.tlsConfig.NextProtos()...)) + } listener = aTLS.NewListener(listener, s.tlsConfig) } return s.httpServer.Serve(listener)