Migrate httputil.ReverseProxy from Director to Rewrite#3603
Draft
zackverham wants to merge 3 commits intomainfrom
Draft
Migrate httputil.ReverseProxy from Director to Rewrite#3603zackverham wants to merge 3 commits intomainfrom
zackverham wants to merge 3 commits intomainfrom
Conversation
Director was deprecated in Go 1.26. This migrates to the newer Rewrite function which provides cleaner separation between inbound and outbound requests via the ProxyRequest type. Changes: - Replace Director field with Rewrite function - Remove baseProxy intermediate proxy (no longer needed) - Store targetURL as *url.URL instead of string - Use pr.SetURL() for URL rewriting instead of calling base Director - Inline stripSourcePrefix logic into rewrite() and proxyURL() Closes #3572 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comprehensive test suite covering: - Basic proxying functionality - Path stripping (sourcePath removal) - Query string preservation - Cookie stripping (security) - Host header setting - Referer header rewriting - Location header rewriting for redirects - Error handling (502 Bad Gateway) - POST request body forwarding - proxyURL helper function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a go deprecation that was introduced by go 1.26. Interestingly, it looks like there was never any test coverage for the proxy package, so this PR also adds test coverage we were missing.
Directorfield to the newerRewritefunction inhttputil.ReverseProxyDirectorwas deprecated in Go 1.26Rewritefunction provides cleaner separation between inbound and outbound requests via theProxyRequesttypeChanges
Directorfield withRewritefunctionbaseProxyintermediate proxy (no longer needed)targetURLas*url.URLinstead ofstringpr.SetURL()for URL rewriting instead of calling base DirectorstripSourcePrefixlogic intorewrite()andproxyURL()Key Differences
func(req *http.Request)func(pr *httputil.ProxyRequest)req(clone)pr.In(original),pr.Out(to modify)Directorpr.SetURL(targetURL)Test Coverage Added
Added 17 tests covering all proxy functionality:
TestBasicProxyTestPathStrippingsourcePathis removed from request pathsTestPathStrippingToRootTestQueryStringPreservedTestCookiesStrippedTestHostHeaderSetTestRefererRewrittenTestRefererEmptyTestLocationHeaderRewrittenTestLocationHeaderRelativeUnchangedTestErrorHandlerTestPostRequestBodyTestProxyURLproxyURL()helperTestProxyURLWithQueryStringTestProxyURLToRootTestProxyURLInvalidURLTestOtherHeadersPreservedTest Plan
Closes #3572
🤖 Generated with Claude Code