package eu.friedcutlet.yokan.services.http import io.ktor.client.engine.darwin.Darwin import platform.Foundation.* // NSURLSession resolves hosts itself; [platformSupportsCustomDns] hides the DNS settings. internal actual val platformSupportsCustomDns: Boolean = false internal actual fun createDefaultPlatformHttpClientEngine(resolveHost: HostResolver?): io.ktor.client.engine.HttpClientEngine = Darwin.create() @OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) internal actual fun createIsolatedPlatformHttpClientEngine(resolveHost: HostResolver?): io.ktor.client.engine.HttpClientEngine = Darwin.create { configureSession { HTTPCookieStorage = null HTTPShouldSetCookies = false URLCredentialStorage = null URLCache = null } configureRequest { setHTTPShouldHandleCookies(false) } handleChallenge { _, _, challenge, complete -> // Keep normal TLS verification; never ask the OS for another profile's saved HTTP/client // certificate credentials. Explicit profile Authorization headers still work normally. val disposition = if (challenge.protectionSpace.authenticationMethod == platform.Foundation.NSURLAuthenticationMethodServerTrust) platform.Foundation.NSURLSessionAuthChallengePerformDefaultHandling else platform.Foundation.NSURLSessionAuthChallengeCancelAuthenticationChallenge complete(disposition, null) } }