package webmiddleware import ( "fmt" "net/http" "git.mstar.dev/mstar/linstrom/config" ) func AddUpgradeHeader(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.ProtoMajor { case 1: // Always offer upgrade to http2 headerText := fmt.Sprintf( "h2=\":%d\"; ma=3600", config.GlobalConfig.General.GetFinalPublicPort(), ) // Offer upgrade to http3 if enabled if config.GlobalConfig.Experimental.Http3Support && config.GlobalConfig.SSL.HandleSSL { headerText = fmt.Sprintf( "h3=\":%d\"; ma=3600, %s", config.GlobalConfig.General.GetFinalPublicPort(), headerText, ) } w.Header().Add("Alt-Svc", headerText) case 2: // Offer upgrade to http3 if enabled if config.GlobalConfig.Experimental.Http3Support && config.GlobalConfig.SSL.HandleSSL { headerText := fmt.Sprintf( "h3=\":%d\"; ma=3600", config.GlobalConfig.General.GetFinalPublicPort(), ) w.Header().Add("Alt-Svc", headerText) } } h.ServeHTTP(w, r) }) }