Some checks are pending
/ docker (push) Waiting to run
- Uses certificate and key files provided by admin in config - Let's Encrypt integration planned, but not even close to working - Initial HTTP3 Support added
40 lines
1 KiB
Go
40 lines
1 KiB
Go
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)
|
|
})
|
|
}
|