fix: replace deprecated proxy.Director with Rewrite in reverse proxy#15
Conversation
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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de3965037c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Rewrite: func(r *httputil.ProxyRequest) { | ||
| r.SetURL(target) | ||
| r.Out.Host = target.Host |
There was a problem hiding this comment.
Restore forwarded headers in Rewrite proxy path
Switching from Director to Rewrite changes header behavior: with Rewrite, Forwarded/X-Forwarded-* headers are stripped before your callback and are not re-added unless ProxyRequest.SetXForwarded() is called. The previous Director-based proxy automatically populated X-Forwarded-For, so this commit drops client forwarding metadata for all proxied requests. Upstreams that rely on those headers for IP-aware auth/rate-limiting/auditing will now see missing or incorrect client identity.
Useful? React with 👍 / 👎.
Summary
httputil.ReverseProxy.DirectorwithReverseProxy.Rewriteinpkg/proxy/server.goDirectoris deprecated since Go 1.26 (staticcheck SA1019); golangci-lint flags it as an error, blocking the go-weekly-rollup Dependabot PRRewriteachieves identical Host-preservation behaviour (r.SetURL(target)+r.Out.Host = target.Host) and has been available since Go 1.20CHANGELOG.mdUnreleasedThis unblocks Dependabot PR #13 (go-weekly-rollup) which exposed the deprecation via a Go toolchain bump.
Test plan
go build ./pkg/proxy/...passesgo test ./pkg/proxy/...passes (all tests green)