cmd/site: opportunistic onion support

This commit is contained in:
Cadey Ratio 2019-02-17 08:32:38 -08:00
parent 20c08e68d1
commit 193c5e1635
2 changed files with 20 additions and 1 deletions

19
cmd/site/altonions.go Normal file
View File

@ -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)
})
}

View File

@ -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 {