Skip to content

[bug]: RetryableHost URL path silently discarded — custom hosts like gateway.example.com/algolia/v3 unusable #890

@DimDL

Description

@DimDL

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions