🎨 Support HTTP/2 over HTTPS (#17500)

This commit is contained in:
Jeffrey Chen
2026-04-16 08:23:58 +08:00
committed by GitHub
parent 0a0a4a3b22
commit 0456ea154e
2 changed files with 4 additions and 2 deletions

View File

@@ -241,12 +241,13 @@ func Serve(fastMode bool, cookieKey string) {
// 反代服务器启动失败不影响核心服务器启动
}()
httpHandler := ginServer.Handler()
util.HttpServer = &http.Server{
Handler: ginServer,
Handler: httpHandler,
}
if useTLS && (util.FixedPort == util.ServerPort || util.IsPortOpen(util.FixedPort)) {
if err = util.ServeMultiplexed(ln, ginServer, certPath, keyPath, util.HttpServer); err != nil {
if err = util.ServeMultiplexed(ln, httpHandler, certPath, keyPath, util.HttpServer); err != nil {
if errors.Is(err, http.ErrServerClosed) || errors.Is(err, cmux.ErrListenerClosed) {
return
}

View File

@@ -24,6 +24,7 @@ func ServeMultiplexed(ln net.Listener, handler http.Handler, certPath, keyPath s
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
NextProtos: []string{"h2", "http/1.1"},
}
tlsListener := tls.NewListener(tlsL, tlsConfig)