remove http/1.1 from alpn if h1 is disabled

This commit is contained in:
Weidi Deng 2025-04-28 18:27:01 +08:00 committed by WeidiDeng
parent 92ea784712
commit c28bab9cb3
No known key found for this signature in database
GPG Key ID: 25F87CE1741EC7CD

View File

@ -420,6 +420,25 @@ func (app *App) Validate() error {
return nil return nil
} }
func removeTLSALPN(srv *Server, target string) {
for _, cp := range srv.TLSConnPolicies {
// the TLSConfig was already provisioned, so... manually remove it
for i, np := range cp.TLSConfig.NextProtos {
if np == target {
cp.TLSConfig.NextProtos = append(cp.TLSConfig.NextProtos[:i], cp.TLSConfig.NextProtos[i+1:]...)
break
}
}
// remove it from the parent connection policy too, just to keep things tidy
for i, alpn := range cp.ALPN {
if alpn == target {
cp.ALPN = append(cp.ALPN[:i], cp.ALPN[i+1:]...)
break
}
}
}
}
// Start runs the app. It finishes automatic HTTPS if enabled, // Start runs the app. It finishes automatic HTTPS if enabled,
// including management of certificates. // including management of certificates.
func (app *App) Start() error { func (app *App) Start() error {
@ -447,22 +466,10 @@ func (app *App) Start() error {
// disable HTTP/2, which we enabled by default during provisioning // disable HTTP/2, which we enabled by default during provisioning
if !srv.protocol("h2") { if !srv.protocol("h2") {
srv.server.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler)) srv.server.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler))
for _, cp := range srv.TLSConnPolicies { removeTLSALPN(srv, "h2")
// the TLSConfig was already provisioned, so... manually remove it
for i, np := range cp.TLSConfig.NextProtos {
if np == "h2" {
cp.TLSConfig.NextProtos = append(cp.TLSConfig.NextProtos[:i], cp.TLSConfig.NextProtos[i+1:]...)
break
}
}
// remove it from the parent connection policy too, just to keep things tidy
for i, alpn := range cp.ALPN {
if alpn == "h2" {
cp.ALPN = append(cp.ALPN[:i], cp.ALPN[i+1:]...)
break
}
}
} }
if !srv.protocol("h1") {
removeTLSALPN(srv, "http/1.1")
} }
// configure the http versions the server will serve // configure the http versions the server will serve