Fix tls config for h2 server

This commit is contained in:
世界 2022-11-26 14:46:20 +08:00
parent bf20ff84b5
commit ee3cd49aa5
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 10 additions and 2 deletions

View file

@ -53,8 +53,8 @@ func NewServer(ctx context.Context, options option.V2RayGRPCOptions, tlsConfig t
if err != nil {
return nil, err
}
if !common.Contains(stdConfig.NextProtos, "h2") {
stdConfig.NextProtos = append(stdConfig.NextProtos, "h2")
if len(stdConfig.NextProtos) == 0 {
stdConfig.NextProtos = []string{http2.NextProtoTLS}
}
server.httpServer.TLSConfig = stdConfig
}
@ -96,10 +96,14 @@ func (s *Server) badRequest(request *http.Request, err error) {
}
func (s *Server) Serve(listener net.Listener) error {
fixTLSConfig := s.httpServer.TLSConfig == nil
err := http2.ConfigureServer(s.httpServer, s.h2Server)
if err != nil {
return err
}
if fixTLSConfig {
s.httpServer.TLSConfig = nil
}
if s.httpServer.TLSConfig == nil {
return s.httpServer.Serve(listener)
} else {

View file

@ -133,10 +133,14 @@ func (s *Server) badRequest(request *http.Request, err error) {
}
func (s *Server) Serve(listener net.Listener) error {
fixTLSConfig := s.httpServer.TLSConfig == nil
err := http2.ConfigureServer(s.httpServer, s.h2Server)
if err != nil {
return err
}
if fixTLSConfig {
s.httpServer.TLSConfig = nil
}
if s.httpServer.TLSConfig == nil {
return s.httpServer.Serve(listener)
} else {