Add initial tls support
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
This commit is contained in:
Melody Becker 2025-05-27 14:06:08 +02:00
parent 68d7a5e8c3
commit 9151bfb3be
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
6 changed files with 250 additions and 42 deletions

View file

@ -0,0 +1,40 @@
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)
})
}