Skip to content

HTTP Client Config #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 6, 2025
Merged

HTTP Client Config #229

merged 15 commits into from
Aug 6, 2025

Conversation

stevensJourney
Copy link
Contributor

@stevensJourney stevensJourney commented Jul 23, 2025

Overview

This PR allows configuring the Ktor networking client we use for PowerSync connections.

This currently allows for a broad range of configuration, including:

  • Installing additional Ktor plugins. E.g the Logging pluging or Custom plugins.
  • Customising request headers etc via the DefaultRequest plugin.

Todos And Open Questions

  • Verify Websocket logging - this seems to currently be quite limited Websockets are no longer used.

  • Gauge the impact of exposing and depending on Ktor in our public SyncOptions API for Swift

The addition of this work increased the release XCFramework by 6MB. The header file increased by 6KB.
This is relatively small compared to the current sizes.

Main Branch

❯  du -sh PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework
228M    PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework
❯  du -sh PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework/ios-arm64/PowerSyncKotlin.framework/Headers/PowerSyncKotlin.h
272K    PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework/ios-arm64/PowerSyncKotlin.framework/Headers/PowerSyncKotlin.h

This Branch

❯ du -sh PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework
234M    PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework
❯ du -sh PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework/ios-arm64/PowerSyncKotlin.framework/Headers/PowerSyncKotlin.h
276K    PowerSyncKotlin/build/XCFrameworks/release/PowerSyncKotlin.xcframework/ios-arm64/PowerSyncKotlin.framework/Headers/PowerSyncKotlin.h
  • Confirm if there is an actual use case for providing an existing Ktor client, versus hooking in to the configuration process of a new client.

The ability to use a provided client has been marked as experimental. We could mark this as a delicate API after an initial experimental release.

  • Investigate formatting changes (might be an issue with my dev setup)

I could not find any issues with my current setup. I think Android Studio might apply formatting differently compared to manual ktlint invocations - currently using the Android studio ktlint plugin.

Demo

The Ktor Logging plugin has been added to the Supabase Todolist demo. A sample log of the HTTP request headers is below

2025-07-23 09:25:33.516 11804-11844 System.out              com.powersync.demos                  I  Authorization=[Token token]
2025-07-23 09:25:33.516 11804-11844 System.out              com.powersync.demos                  I  User-Agent=[PowerSync Kotlin SDK v1.3.0 (Android 29)]
2025-07-23 09:25:33.516 11804-11844 System.out              com.powersync.demos                  I  Accept-Charset=[UTF-8]
2025-07-23 09:25:33.516 11804-11844 System.out              com.powersync.demos                  I  Accept=[*/*]
2025-07-23 09:26:03.535 11804-11844 System.out              com.powersync.demos                  I  Response headers:
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  access-control-allow-origin=[*]
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  access-control-expose-headers=[Content-Type]
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  connection=[keep-alive]
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  content-length=[2419]
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  content-type=[application/json; charset=utf-8]
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  date=[Wed, 23 Jul 2025 07:26:42 GMT]
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  keep-alive=[timeout=72]
2025-07-23 09:26:03.536 11804-11844 System.out              com.powersync.demos                  I  vary=[Origin]

Swift

The Swift SDK now exposes a limited and controlled subset of plugin functionality by exposing logging PowerSync network requests. powersync-ja/powersync-swift#63

Copy link
Contributor

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

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

This looks nice 👍

One thing I'm wondering about is if we can use this to remove the createClient field in SyncStream and PowerSyncDatabaseImpl (since we now have a proper option for this). I've added those for tests, but it looks like we can now pass the test engine via connection options instead.
(and then as a fallback when the engine option is null, use defaultHttpClient from the companion or just inline the HttpClient call)

# Conflicts:
#	core/src/commonIntegrationTest/kotlin/com/powersync/testutils/TestUtils.kt
#	core/src/commonMain/kotlin/com/powersync/sync/SyncOptions.kt
#	core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt
# Conflicts:
#	core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt
#	gradle.properties
# Conflicts:
#	demos/hello-powersync/composeApp/build.gradle.kts
#	demos/hello-powersync/composeApp/composeApp.podspec
#	demos/hello-powersync/composeApp/src/commonMain/kotlin/com/powersync/demos/PowerSync.kt
#	demos/hello-powersync/iosApp/Podfile.lock
Copy link
Contributor

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

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

This looks good to me apart from some documentation nits.

@stevensJourney stevensJourney changed the title [WIP] HTTP Client Config HTTP Client Config Aug 6, 2025
@stevensJourney stevensJourney marked this pull request as ready for review August 6, 2025 08:46
Copy link
Contributor

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

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

Happy with these changes, looks like a good addition to have 👍

@stevensJourney stevensJourney merged commit a7863e8 into main Aug 6, 2025
5 checks passed
@stevensJourney stevensJourney deleted the client-logging branch August 6, 2025 09:07
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.

2 participants