about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-05-24 23:39:30 +0200
committerAlan Pearce2024-05-24 23:39:30 +0200
commitc8b38ee1bf5aa59799074db85eb549a0e3f541e4 (patch)
tree2c7716afc7d7c01efa4fa49bb49035165fa9f6d4
parente19e9de02f4e0bf5b266f467fc67a0eebc6d3f62 (diff)
downloadwebsite-c8b38ee1bf5aa59799074db85eb549a0e3f541e4.tar.lz
website-c8b38ee1bf5aa59799074db85eb549a0e3f541e4.tar.zst
website-c8b38ee1bf5aa59799074db85eb549a0e3f541e4.zip
fix Host weirdness on fly with h2c
-rw-r--r--internal/server/server.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/internal/server/server.go b/internal/server/server.go
index b35b6dd..61d5790 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -52,6 +52,12 @@ func applyDevModeOverrides(config *cfg.Config, listenAddress string) {
 
 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)
 	})