Skip to content

fix: preserve base URL path prefix when resolving endpoint paths - #69

Open
Fiona2016 wants to merge 2 commits into
mainfrom
fix/base-url-path-prefix
Open

fix: preserve base URL path prefix when resolving endpoint paths#69
Fiona2016 wants to merge 2 commits into
mainfrom
fix/base-url-path-prefix

Conversation

@Fiona2016

Copy link
Copy Markdown

Problem

WithBaseURL passes the parsed URL straight to url.URL.ResolveReference. Under RFC 3986 relative resolution, a base path without a trailing slash has its last segment replaced rather than appended to: with base https://gateway.example.com/api, the endpoint /rum/data/query resolved to https://gateway.example.com/rum/data/query — the /api prefix 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 / in WithBaseURL so relative resolution appends endpoint paths. Both request builders (newRequestWithAppKey and the multipart upload path) resolve against the same BaseURL, 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

  • New TestWithBaseURLPreservesPathPrefix table: default host, trailing slash, single-segment prefix (/api), and multi-segment prefix (/a/b), asserting the full resolved request URL via newRequest.
  • Updated the existing BaseURL.String() assertion for the normalized form.
  • Full suite passes; verified end-to-end against a gateway mounted under a path prefix (stock build fails with 405, patched build succeeds).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant