diff --git a/cmd/site/altonions.go b/cmd/site/altonions.go new file mode 100644 index 0000000..8ea8bce --- /dev/null +++ b/cmd/site/altonions.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "net/http" + "os" +) + +var altOnionServer = os.Getenv("ALT_ONION_SERVER") + +func altOnionHandler(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if altOnionServer != "" { + w.Header().Set("Alt-Svc", fmt.Sprintf(`h2="%s:443"; ma=86400; persist=1`, altOnionServer)) + } + + next.ServeHTTP(w, r) + }) +} diff --git a/cmd/site/main.go b/cmd/site/main.go index ec9648b..c00f22a 100644 --- a/cmd/site/main.go +++ b/cmd/site/main.go @@ -75,7 +75,7 @@ func main() { } ln.Log(context.Background(), ln.F{"action": "http_listening", "port": port}) - http.ListenAndServe(":"+port, s) + http.ListenAndServe(":"+port, altOnionHandler(s)) } func requestIDMiddleware(next http.Handler) http.Handler {