ktor icon indicating copy to clipboard operation
ktor copied to clipboard

KTOR-6182 Support throwing `UnknownServiceException` if there is no cleartext traffic permitted

Open Goooler opened this issue 2 years ago • 9 comments

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

Goooler avatar Aug 11 '23 10:08 Goooler

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.

Goooler avatar Aug 15 '23 13:08 Goooler

What do you mean? You mean I should move Platform into a new module under ktor-client/ktor-client-plugins?

Goooler avatar Jan 12 '24 12:01 Goooler

Yep! We also can install this plugin by default in case the VM is Dalvik

e5l avatar Jan 12 '24 12:01 e5l

Seems the style check failure is not related to my change.

Goooler avatar Jan 17 '24 10:01 Goooler