fix Host weirdness on fly with h2c
Alan Pearce alan@alanpearce.eu
Fri, 24 May 2024 23:39:30 +0200
1 files changed, 6 insertions(+), 0 deletions(-)
jump to
M internal/server/server.go → internal/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) })