Skip to content

refactor: Add httpClientOverride parameter to ServerpodClientShared - #5134

Merged
vfiruz97 merged 5 commits into
serverpod:mainfrom
vfiruz97:refactor/add-with-credentials-param-to-serverpod-client
May 18, 2026
Merged

vfiruz97 merged 5 commits into
serverpod:mainfrom
vfiruz97:refactor/add-with-credentials-param-to-serverpod-client

Conversation

@vfiruz97

@vfiruz97 vfiruz97 commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Adds an optional http.Client? httpClientOverride parameter to ServerpodClientShared and all generated client constructors.

If no override is provided the default http.Client() is used on web and an IOClient (wrapping dart:io's HttpClient) is used on native. If an override is provided it is used directly, giving users full control over the underlying HTTP transport.

This allows passing any http.Client implementation — including platform-native clients from packages such as cupertino_http (NSURLSession on iOS/macOS) or cronet_http (Cronet on Android), as well as configuring browser-specific behaviour on web.

Examples:

Enable CORS credentials on web:

Client(
  serverUrl,
  httpClientOverride: BrowserClient()..withCredentials = true,
)
  ..connectivityMonitor = FlutterConnectivityMonitor()
  ..authSessionManager = FlutterAuthSessionManager();
  

Use platform-native HTTP on iOS/macOS ([cupertino_http]):

Client(
  serverUrl,
  httpClientOverride: CupertinoClient.defaultSessionConfiguration(),
);

Use Cronet on Android ([cronet_http]):

Client(
  serverUrl,
  httpClientOverride: CronetClient.fromCronetEngine(engine),
);

Note: httpClientOverride and securityContext cannot be set simultaneously — an assertion enforces this since securityContext is only meaningful when the framework builds the client internally.

Fixes #4850

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

No breaking changes.

@vfiruz97
vfiruz97 requested review from marcelomendoncasoares and nielsenko and removed request for nielsenko May 14, 2026 14:27
@vfiruz97 vfiruz97 changed the title refactor: Adds withCredentials param to serverpod client. refactor: Add httpClientOverride parameter to ServerpodClientShared May 15, 2026

@nielsenko nielsenko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@vfiruz97
vfiruz97 merged commit 29dd649 into serverpod:main May 18, 2026
158 of 160 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow injecting a custom ServerpodClientRequestDelegate

2 participants