all repos — website @ c8b38ee1bf5aa59799074db85eb549a0e3f541e4

My website

fix Host weirdness on fly with h2c
Alan Pearce alan@alanpearce.eu
Fri, 24 May 2024 23:39:30 +0200
commit

c8b38ee1bf5aa59799074db85eb549a0e3f541e4

parent

e19e9de02f4e0bf5b266f467fc67a0eebc6d3f62

1 files changed, 6 insertions(+), 0 deletions(-)

jump to
M internal/server/server.gointernal/server/server.go
@@ -52,6 +52,12 @@ } 
 func serverHeaderHandler(wrappedHandler http.Handler) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		if r.ProtoMajor >= 2 && r.Header.Get("Host") != "" {
+			// net/http does this for HTTP/1.1, but not h2c
+			// TODO: check with HTTP/2.0 (i.e. with TLS)
+			r.Host = r.Header.Get("Host")
+			r.Header.Del("Host")
+		}
 		w.Header().Set("Server", serverHeader)
 		wrappedHandler.ServeHTTP(w, r)
 	})