-
-
Notifications
You must be signed in to change notification settings - Fork 149
feat(network): Add proxy setting to HttpClient #176
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
base: main
Are you sure you want to change the base?
Conversation
Adds a commented-out proxy configuration block to the Ktor `HttpClient` engine settings. This allows for easier enabling and configuration of an HTTP proxy for debugging or network testing purposes.
WalkthroughAdded HTTP engine configuration infrastructure to the GitHub client, including proxy builder imports and an engine block with a commented proxy setup. The proxy configuration remains disabled, preserving current behavior. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
@composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/network/GitHubClient.kt:
- Around line 42-44: The engine { } block in GitHubClient.kt cannot live in
commonMain because Ktor engines are platform-specific; remove the engine { }
configuration from the common HttpClient creation (e.g., from
buildGitHubHttpClient() / HttpClient in GitHubClient) and implement the engine
in platform-specific source sets instead using either an expect/actual
buildGitHubHttpClient() pair or by creating the HttpClient with the platform
engine in androidMain/iosMain and calling a shared function in commonMain to
install common features; also ensure any proxy URL is populated before
re-enabling the proxy line.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/network/GitHubClient.kt
🔇 Additional comments (1)
composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/network/GitHubClient.kt (1)
8-9: Imports are correctly added for proxy support.The imports for
ProxyBuilderandhttpare valid Ktor utilities for proxy configuration. They will be used when the proxy line is uncommented.
| engine { | ||
| // proxy = ProxyBuilder.http("") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's locate and read the GitHubClient.kt file
fd "GitHubClient.kt" --type fRepository: rainxchzed/Github-Store
Length of output: 147
🏁 Script executed:
# Once we have the path, let's examine the code around lines 42-44 and the HttpClient setup
cat -n composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/network/GitHubClient.kt | head -60Repository: rainxchzed/Github-Store
Length of output: 2602
🌐 Web query:
Ktor HttpClient engine block configuration Kotlin Multiplatform commonMain
💡 Result:
Short answer
You cannot configure a platform-specific engine (the engine { ... } block) from commonMain. Engine configuration is platform-specific, so create the HttpClient (or at least supply the engine) in each platform source set and keep common installs/configuration in commonMain.
Why
- Ktor engines are platform-specific and their config types live in platform modules, not commonMain. [1]
- Use expect/actual or provide a factory implemented in platformMain to supply an HttpClient or engine. [2][3]
Minimal patterns
- Preferred — create client per platform, share common setup
- commonMain:
- put shared installs and helper functions that accept HttpClient.
- optionally expose an expect factory.
Example (commonMain)
expect fun createHttpClient(): HttpClient
// shared code uses createHttpClient()
- androidMain / iosMain (actual):
actual fun createHttpClient(): HttpClient = HttpClient(Android) {
// engine-specific options here
engine { connectTimeout = 100_000; socketTimeout = 100_000 }
// common installs also allowed here if desired
}
- Alternative — create engine-less client in common and supply engine in platform
-
commonMain:
fun createSharedClient(configure: HttpClientConfig<>.() -> Unit = {}): HttpClient =
HttpClient { configure(); / shared installs here */ } -
platformMain:
val client = HttpClient(Android) { engine { /* AndroidEngineConfig / }; / call or duplicate shared installs if needed */ }
Notes
- Keep protocol-level installs (Json, Logging, HttpTimeout, Auth) in commonMain. Configure engine details (timeouts, proxy, OkHttp/Android/Darwin options) only in platformMain. [1][3]
- Use expect/actual or dependency injection to avoid duplicating shared install code. [2][3]
Sources
- Ktor client engines and engine configuration. [1]
- Kotlin Multiplatform expect/actual guidance. [2]
- Community discussion confirming engine config must live in platform source sets. [3]
Move engine {} configuration to platform-specific source sets.
Engine configuration is platform-specific in Ktor and cannot be configured in commonMain. The engine {} block requires a concrete engine type, which is not available in the common source set.
Move engine configuration to platform-specific source sets (androidMain, iosMain, etc.) using either:
expect/actualpattern forbuildGitHubHttpClient()- Per-platform HttpClient creation with shared install logic in commonMain
Additionally, ensure the proxy URL is populated (currently an empty string) before uncommenting.
🤖 Prompt for AI Agents
In
@composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/network/GitHubClient.kt
around lines 42 - 44, The engine { } block in GitHubClient.kt cannot live in
commonMain because Ktor engines are platform-specific; remove the engine { }
configuration from the common HttpClient creation (e.g., from
buildGitHubHttpClient() / HttpClient in GitHubClient) and implement the engine
in platform-specific source sets instead using either an expect/actual
buildGitHubHttpClient() pair or by creating the HttpClient with the platform
engine in androidMain/iosMain and calling a shared function in commonMain to
install common features; also ensure any proxy URL is populated before
re-enabling the proxy line.
Adds a commented-out proxy configuration block to the Ktor
HttpClientengine settings. This allows for easier enabling and configuration of an HTTP proxy for debugging or network testing purposes.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.