Skip to content

feat(android): allow custom OkHttpClient via factory#1376

Open
whydidoo wants to merge 2 commits intocallstack:mainfrom
whydidoo:feat/android-okhttp-client-factory
Open

feat(android): allow custom OkHttpClient via factory#1376
whydidoo wants to merge 2 commits intocallstack:mainfrom
whydidoo:feat/android-okhttp-client-factory

Conversation

@whydidoo
Copy link

Replace direct OkHttpClient instantiation with a configurablefactory in companion object, enabling custom client configuration(SSL, interceptors, timeouts) from the host application.

Summary

Currently, RemoteScriptLoader creates a hardcoded OkHttpClient() instance with no way to customize it. This is a problem for apps that need custom HTTP configuration — for example, certificate pinning, custom SSL trust managers, logging interceptors, or proxy settings.

This PR introduces a static okHttpClientFactory lambda in a companion object, allowing host applications to provide their own OkHttpClient instance before any network requests are made:

RemoteScriptLoader.okHttpClientFactory = {
    OkHttpClient.Builder()
        .addInterceptor(loggingInterceptor)
        .sslSocketFactory(sslSocketFactory, trustManager)
        .connectTimeout(30, TimeUnit.SECONDS)
        .build()
}

The client is lazily initialized via by lazy, so the factory is only called once on the first use.

Test plan

  1. Default behavior — verify that without setting okHttpClientFactory, a default OkHttpClient() is used (no regression).
  2. Custom client — set okHttpClientFactory in Application.onCreate() or a React Native module initializer with a custom interceptor, confirm the interceptor is invoked during remote script loading.
  3. Lazy initialization — confirm the factory is called only once, regardless of how many scripts are loaded.

Replace direct OkHttpClient instantiation with a configurablefactory in companion object, enabling
custom client configuration(SSL, interceptors, timeouts) from the host application.
@vercel
Copy link

vercel bot commented Mar 20, 2026

@whydidoo is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 23fc64d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Major
@callstack/repack-plugin-expo-modules Major
@callstack/repack-plugin-nativewind Major
@callstack/repack-plugin-reanimated Major
@callstack/repack-dev-server Major
@callstack/repack-init Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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