cmd/site: opportunistic onion support
This commit is contained in:
parent
20c08e68d1
commit
193c5e1635
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
|
@ -75,7 +75,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ln.Log(context.Background(), ln.F{"action": "http_listening", "port": port})
|
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 {
|
func requestIDMiddleware(next http.Handler) http.Handler {
|
||||||
|
|
Loading…
Reference in New Issue