summaryrefslogtreecommitdiff
path: root/internal/http/headers.go
diff options
context:
space:
mode:
authorspiperac <[email protected]>2026-06-15 06:42:13 +0200
committerspiperac <[email protected]>2026-06-15 06:42:13 +0200
commit0a477fd288d064d265395c88dbd0f261b723804e (patch)
tree9b129f8f41c907285b89ed8385679934bb59c14f /internal/http/headers.go
Initial release
Diffstat (limited to 'internal/http/headers.go')
-rw-r--r--internal/http/headers.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/http/headers.go b/internal/http/headers.go
new file mode 100644
index 0000000..d06d584
--- /dev/null
+++ b/internal/http/headers.go
@@ -0,0 +1,54 @@
+package http
+
+import (
+ "net"
+ "net/http"
+)
+
+// NormalizeHost strips the port from a Host header value when it is the
+// default for the scheme (443 for HTTPS, 80 for HTTP), so that we never
+// send "Host: example.com:443" to an upstream server.
+func NormalizeHost(host string, tls bool) string {
+ h, port, err := net.SplitHostPort(host)
+ if err != nil {
+ return host
+ }
+ if (tls && port == "443") || (!tls && port == "80") {
+ return h
+ }
+ return host
+}
+
+// StripRequestCacheHeaders removes conditional-request headers so the
+// upstream always returns a fresh response.
+func StripRequestCacheHeaders(h http.Header) {
+ h.Del("If-None-Match")
+ h.Del("If-Modified-Since")
+ h.Del("If-Range")
+ h.Del("If-Match")
+ h.Del("If-Unmodified-Since")
+}
+
+// StripResponseCacheHeaders removes caching directives from a response and
+// sets no-store so the browser never serves a stale cached copy.
+func StripResponseCacheHeaders(h http.Header) {
+ h.Del("Cache-Control")
+ h.Del("Expires")
+ h.Del("ETag")
+ h.Del("Last-Modified")
+ h.Del("Pragma")
+ h.Set("Cache-Control", "no-store, no-cache, must-revalidate")
+}
+
+// HopByHop is the set of headers that must not be forwarded to the upstream.
+var HopByHop = map[string]bool{
+ "Connection": true,
+ "Proxy-Connection": true,
+ "Keep-Alive": true,
+ "Proxy-Authenticate": true,
+ "Proxy-Authorization": true,
+ "Te": true,
+ "Trailers": true,
+ "Transfer-Encoding": true,
+ "Upgrade": true,
+}