KTOR-6182 Support throwing `UnknownServiceException` if there is no cleartext traffic permitted
https://youtrack.jetbrains.com/issue/KTOR-6182
This part had been implemented in Okhttp & HttpURLConnection, we just need to patch it for CIO.
Staled some code from: https://github.com/square/okhttp/blob/735ed1a6e5a15042f6d7e8f100fb3c8376f6aa27/okhttp/src/jvmMain/kotlin/okhttp3/internal/connection/RealRoutePlanner.kt#L205-L208 https://github.com/square/okhttp/blob/550cc11989e5117ed3d8afaf20c7b6c419b5351f/okhttp/src/main/kotlin/okhttp3/internal/platform/AndroidPlatform.kt#L105-L148
If we are using CIO to request an HTTP URL on Android 9+, there is no exception thrown (an example here), but thrown with the use of OkHttp or Android engine, cause the isCleartextTrafficPermitted check had been implemented by them, like this, this is a suggested behavior on Android:
This flag is honored on a best effort basis because it's impossible to prevent all cleartext traffic from Android applications given the level of access provided to them.
We should catch up what Okhttp did on Android, to provide the same experience.
What do you mean? You mean I should move Platform into a new module under ktor-client/ktor-client-plugins?
Yep! We also can install this plugin by default in case the VM is Dalvik
Seems the style check failure is not related to my change.