-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat(rt): introduce opaque KMP default HTTP client engine #606
Conversation
Deprecate KtorEngine as synonymous with OkHttp. The `http-client-engine-ktor` is now a utility wrapper for _any_ Ktor compliant engine. The OkHttp engine has been moved to `http-client-engine-default` as the default engine on JVM. BREAKING CHANGE: Use of explicit `httpClientEngine = KtorEngine()` will no longer compile. The default engine will be synonymous with OkHttp making it unnecessary to set this engine. Users should remove this explicit SDK client configuration.
/** | ||
* Factory function to create a new HTTP client engine using the default for the current KMP target | ||
*/ | ||
fun SdkHttpEngine(config: HttpClientEngineConfig = HttpClientEngineConfig.Default): HttpClientEngine = | ||
newDefaultHttpEngine(config) | ||
|
||
fun SdkHttpEngine(block: HttpClientEngineConfig.Builder.() -> Unit): HttpClientEngine { | ||
val builder = HttpClientEngineConfig.Builder().apply(block) | ||
val config = HttpClientEngineConfig(builder) | ||
return SdkHttpEngine(config) | ||
} |
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.
Comment: The name SdkHttpEngine
feels ambiguous and inaccurate to me. Technically the CRT engine is also an "SDK HTTP Engine". It'd be clearer to me if it were DefaultHttpEngine
or something similar.
"use KtorEngine to wrap it. This constructor will be removed in a future release before GA.", | ||
level = DeprecationLevel.ERROR | ||
) | ||
constructor(config: HttpClientEngineConfig = HttpClientEngineConfig.Default) : this(DeprecationEngine) |
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.
Comment: It seems cleaner to throw an error immediately upon invoking KtorEngine()
rather than later:
companion object {
@Suppress("UNUSED_PARAMETER")
@Deprecated(message = "KtorEngine was previously...", level = DeprecationLevel.ERROR)
operator fun invoke(config: HttpClientEngineConfig = HttpClientEngineConfig.Default): KtorEngine =
error("Invoking KtorEngine without an engine is deprecated")
}
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.
It's irrelevant, code doesn't compile if you target this constructor
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Issue #
closes #602
Description of changes
http-client-engine-default
that provides anHttpClientEngine
implementation that works for KMP. This allows us to not hard code against a specific engine (which would require that engine be KMP compatible).%252F
instead of just%2F
when/
was present in a query value. The fix for this was to turn off any encoding by ktor and use the encoding used by the SDK.KtorEngine
intocommon
and make it a utility that wraps any ktor compatible engine rather than being synonymous with a particular engine. See breaking change notes belowBreaking Change
This PR marks the
KtorEngine
constructor as deprecated since it no longer provides a concrete engine. Instead it now wraps some ktor compatible engine.Users that are currently constructing service clients like the above snippet will no longer compile on update. The default engine is now the Ktor OKHttp engine and so the recommended fix would be to simply not override
httpClientEngine
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.