Support custom HTTP clients#424
Draft
simolus3 wants to merge 6 commits into
Draft
Conversation
f6d7872 to
9bfb3ad
Compare
e69c7e6 to
9533e1a
Compare
|
I tested this PR against our self-hosted setup and it solves our CA-trust problem. Returning a package:http IOClient built on an HttpClient with a custom SecurityContext carrying our CA, via the Client Function() factory, connects fine and is fast. The factory covers the self-signed-cert case for us. I also tried a cronet_http client but it was extremely slow in the spawned sync isolate, and I haven't figured out why. We're going with dart:io, which works well. Is there a concrete plan for when this feature will be officially released? Thanks for the great work on this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blocked by #425.
There are a number of cases where users might want to use custom HTTP clients with the PowerSync SDK, such as:
/sync/streamresponses for the middleware-based encryption approach.This PR adds support for this through an
httpClientfield onSyncOptions. It can be set to aClient Function()acting as a factory for HTTP clients. On native platforms, we send that factory function through a send port to reconstruct a client on the other end.On the web, the whole thing is a little tricky. We can't send Dart objects to a worker, so this serializes HTTP requests and responses via
postMessagecalls:AsyncIterableinterface through message ports.We only do this when custom clients are installed, since
postMessagemight add overhead (probably not too much since we can transfer blobs though).Note: According to mdn,
ReadableStreams are supposed to be transferrable, which would have made the whole implementation much simpler. But also according to mdn,ReadableStreams aren't transferrable on Safari :/TODOs: