From de3965037c21a13c6cb9283c69e7c1ea6a72a958 Mon Sep 17 00:00:00 2001 From: Ogulcan Aydogan Date: Tue, 12 May 2026 22:04:12 +0100 Subject: [PATCH] fix: replace deprecated proxy.Director with Rewrite in reverse proxy httputil.ReverseProxy.Director is deprecated since Go 1.26 (staticcheck SA1019). ReverseProxy.Rewrite achieves the same Host-preservation behaviour and has been available since Go 1.20. This unblocks the go-weekly-rollup Dependabot PR that bumped dependencies requiring the newer Go toolchain where staticcheck flags the deprecated usage. --- CHANGELOG.md | 3 +++ pkg/proxy/server.go | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c73bc8..8793029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Replace deprecated `httputil.ReverseProxy.Director` with `Rewrite` in `pkg/proxy/server.go`; `Director` is deprecated since Go 1.26 (SA1019); `Rewrite` achieves the same Host-preservation behaviour and has been available since Go 1.20. + ## [1.3.0] - 2026-03-08 ### Added diff --git a/pkg/proxy/server.go b/pkg/proxy/server.go index ae82057..d8b71a3 100644 --- a/pkg/proxy/server.go +++ b/pkg/proxy/server.go @@ -35,13 +35,11 @@ func StartServer(opts ServerOptions, d detector.Detector) error { Level: slog.LevelInfo, })) - proxy := httputil.NewSingleHostReverseProxy(target) - - // Preserve the original Host header - originalDirector := proxy.Director - proxy.Director = func(req *http.Request) { - originalDirector(req) - req.Host = target.Host + proxy := &httputil.ReverseProxy{ + Rewrite: func(r *httputil.ProxyRequest) { + r.SetURL(target) + r.Out.Host = target.Host + }, } action := ParseAction(opts.Action)