fix: preserve base URL path prefix when resolving endpoint paths - #69
Open
Fiona2016 wants to merge 2 commits into
Open
fix: preserve base URL path prefix when resolving endpoint paths#69Fiona2016 wants to merge 2 commits into
Fiona2016 wants to merge 2 commits into
Conversation
WithBaseURL fed the parsed URL directly to url.URL.ResolveReference, whose RFC 3986 semantics replace the last path segment when the base path lacks a trailing slash: base "https://gateway.example.com/api" resolved "/rum/data/query" to "/rum/data/query" instead of "/api/rum/data/query", leaving deployments that serve the API under a path prefix unreachable. Normalize the base path to end with "/" so relative resolution appends endpoint paths; both newRequestWithAppKey and the multipart upload path resolve against the same BaseURL.
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.
Problem
WithBaseURLpasses the parsed URL straight tourl.URL.ResolveReference. Under RFC 3986 relative resolution, a base path without a trailing slash has its last segment replaced rather than appended to: with basehttps://gateway.example.com/api, the endpoint/rum/data/queryresolved tohttps://gateway.example.com/rum/data/query— the/apiprefix silently disappeared. Any deployment that serves the Flashduty API under a path prefix was unreachable, and the resulting error (an HTML 405 from whatever serves the root path) pointed users in the wrong direction.Fix
Normalize the base path to end with
/inWithBaseURLso relative resolution appends endpoint paths. Both request builders (newRequestWithAppKeyand the multipart upload path) resolve against the sameBaseURL, so one normalization covers both.The default base URL (
https://api.flashcat.cloud, empty path) is unaffected: RFC 3986 already special-cases an empty base path with a defined authority, so resolution behaves as before for existing users.Tests
TestWithBaseURLPreservesPathPrefixtable: default host, trailing slash, single-segment prefix (/api), and multi-segment prefix (/a/b), asserting the full resolved request URL vianewRequest.BaseURL.String()assertion for the normalized form.