Description
When configuring a SearchClient with custom hosts via RetryableHost(url:callType:), any path component in the provided URL is silently ignored. This makes it impossible to route Algolia requests through a reverse proxy or API gateway that uses a path prefix (e.g. https://gateway.example.com/algolia/v3).
Example:
Custom Host: https://example.com/a/b/c/d
SDK path: /1/indexes/myCustomIndex/query
Expected: https://example.com/a/b/c/d/1/indexes/myCustomIndex/query
Actual: https://example.com/1/indexes/myCustomIndex/query
=> /a/b/c/d/ is dropped, making HTTP request fail
Cause:
Transporter.swift line 90:
guard let url = urlComponents.url(relativeTo: host.url) else {
throw AlgoliaError.requestError(GenericError(description: "Malformed URL"))
}
// urlComponents holds path, aka /1/indexes/myCustomIndex/query
// host value is https://example.com/a/b/c/d
// but url produced is https://example.com/1/indexes/myCustomIndex/query (a/b/c/d is dropped)
Suggested fix
Prepend the base URL's path before setting percentEncodedPath:
let basePath = host.url.path // e.g. "/algolia/v3" or ""
urlComponents.percentEncodedPath = basePath + path
… or any appropriate URL construction of your choice.
Steps to reproduce
let config = try SearchClientConfiguration(
appID: "APP_ID",
apiKey: "API_KEY",
hosts: [RetryableHost(url: URL(string: "https://my-proxy.example.com/algolia/v3")!, callType: .read)]
)
let client = SearchClient(configuration: config)
// Any search request will hit: https://my-proxy.example.com/1/indexes/...
// instead of: https://my-proxy.example.com/algolia/v3/1/indexes/...
Workaround
Register a custom URLProtocol that intercepts requests to the target host and re-injects the path prefix before forwarding. This works but is fragile and shouldn't be necessary.
Environment
algoliasearch-client-swift v 9.41.2, iOS 26
Client
All
Version
9.41.2
Relevant log output
Description
When configuring a
SearchClientwith custom hosts viaRetryableHost(url:callType:), any path component in the provided URL is silently ignored. This makes it impossible to route Algolia requests through a reverse proxy or API gateway that uses a path prefix (e.g.https://gateway.example.com/algolia/v3).Example:
Custom Host:
https://example.com/a/b/c/dSDK path:
/1/indexes/myCustomIndex/queryExpected:
https://example.com/a/b/c/d/1/indexes/myCustomIndex/queryActual:
https://example.com/1/indexes/myCustomIndex/query=>
/a/b/c/d/is dropped, making HTTP request failCause:
Transporter.swift line 90:
//
urlComponentsholds path, aka/1/indexes/myCustomIndex/query//
hostvalue ishttps://example.com/a/b/c/d// but
urlproduced ishttps://example.com/1/indexes/myCustomIndex/query(a/b/c/d is dropped)Suggested fix
Prepend the base URL's path before setting percentEncodedPath:
… or any appropriate URL construction of your choice.
Steps to reproduce
Workaround
Register a custom
URLProtocolthat intercepts requests to the target host and re-injects the path prefix before forwarding. This works but is fragile and shouldn't be necessary.Environment
algoliasearch-client-swift v 9.41.2, iOS 26
Client
All
Version
9.41.2
Relevant log output