-
Notifications
You must be signed in to change notification settings - Fork 132
Description
Description
Currently, the Config class in the Meilisearch Java SDK initializes a default HttpClient as a final field, with no way to inject a custom OkHttpClient instance. This prevents users from configuring advanced HTTP settings such as custom timeouts, connection pooling, interceptors (e.g., logging, retry logic), or proxy configurations — which are essential for production-grade applications.
Basic example
I would like to be able to pass a pre-configured OkHttpClient to the Config class, like this:
OkHttpClient customClient = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.addInterceptor(new LoggingInterceptor())
.retryOnConnectionFailure(true)
.build();
Config config = new Config("http://localhost:7700", "masterKey", customClient);
MeiliSearchClient client = new MeiliSearchClient(config);
Currently, this is not possible because Config only accepts hostUrl and apiKey, and internally creates a fixed HttpClient. Adding a constructor that accepts an OkHttpClient (or HttpClient interface) would enable full control over HTTP behavior.
Other
This change would improve flexibility for enterprise users who need custom HTTP behavior (e.g., TLS config, corporate proxies, monitoring).
The change is backward-compatible — existing code continues to work with the default constructor.