Repository navigation
fix: strip fragments and empty queries from client base URLs - #1292
Open
waw666waw666 wants to merge 1 commit into
Open
waw666waw666 wants to merge 1 commit into
waw666waw666 wants to merge 1 commit into
Conversation
Load balancer base URLs have stripped fragments and empty queries since go-resty#1272, because request URLs are composed by concatenating the base URL with the request path. Client.SetBaseURL stored the URL verbatim, so the same corruption applied there: - SetBaseURL("https://host/api#frag") + Get("/users") sent the request to /api; "/users" was swallowed into the fragment. - SetBaseURL("https://host/api?") + Get("/users") turned the path into the query string. Sanitize the base URL in SetBaseURL the same way extractBaseURL sanitizes load balancer bases: parse it, clear Fragment/RawFragment and ForceQuery, and store the result. Well-formed base URLs, including a trailing slash, are stored unchanged, and an unparseable URL is stored as-is so its error still surfaces at request time.
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.
#1272 stripped fragments and empty queries from load balancer base URLs because request URLs are composed by concatenating the base URL with the request path. Client.SetBaseURL stored the URL verbatim, so the same corruption applies to the main path: SetBaseURL("https://host/api#frag") + Get("/users") sends the request to /api (the path is swallowed into the fragment), and SetBaseURL("https://host/api?") + Get("/users") turns the path into the query string.
SetBaseURL now sanitizes the URL the same way extractBaseURL does for load balancer bases — parse, clear Fragment/RawFragment and ForceQuery, store the result (new sanitizeBaseURL helper in client.go). Well-formed base URLs, including a trailing slash, are stored unchanged; an unparseable URL is stored as-is so its error still surfaces at request time.
new baseurl_sanitize_test.go spins up an httptest server and asserts the received path/query for base URLs ending in /api#frag, /api?, /api# and /api, plus stored-value assertions for valid, fragment, empty-query and unparseable base URLs. Commands:
go test -run 'TestSetBaseURL' -count=1 -v .and fullgo test -count=1 .(only the pre-existing timing-sensitive TestTraceInfoOnTimeout* failures, identical before and after).