Release 0.4.0: preserve base-URL path prefixes - #6
Merged
Conversation
Fixed: - A base URL with a path prefix (e.g. https://api.example.com/v1) had its prefix dropped when an endpoint path was joined, because an absolute path replaces the base path per RFC 3986. The base is now normalized to a trailing `/` and endpoint paths are joined relative to it, so `/v1` + `/users` → `/v1/users`. Bases without a path prefix are unaffected. Uses existing primitives only (Url::set_path, Url::join, str::trim_start_matches, and the existing segment encoder) — no new dependency. Tests: base {no prefix, /v1, /v1/} x path {params, no params, param with `/`} plus a no-prefix regression test.
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
Fixes a long-standing footgun: a base URL with a path prefix (e.g.
https://api.example.com/v1) had its prefix silently dropped, so beckon requested/usersinstead of/v1/users— mysterious 404s against APIs like Stripe (/v1) on the very first call.Root cause
Endpoint paths carry a leading
/(absolute references), andUrl::joinfollows RFC 3986 — an absolute path replaces the base path. (Not a reqwest/url bug; base-URL-as-prefix is a known request reqwest declined, left to userland. beckon is that layer.)Fix
Two small changes, no new dependency — reuses
Url::set_path,Url::join,str::trim_start_matches, and the existing segment encoder:/once, at construction (with_client;newdelegates to it)./).…/v1/users…/users❌…/v1/users✅…/v1//users…/users❌…/v1/users✅https://api.x.com/users…/users✅…/users✅ (unchanged)Bases without a path prefix — which every example/test uses — are byte-for-byte unchanged, so in practice this breaks no one; it's shipped as a minor with a changelog note because it is a behavior change.
Tests
Matrix added: base {no prefix,
/v1,/v1/} × path {no params, params, param containing/} + a no-prefix regression test. Verified on the CI toolchain (cargo +stable): fmt, clippy-D warnings, 33 tests + doctests — all green.