small fix for password setting up in authenticator

This commit is contained in:
InsanusMokrassar 2023-10-11 21:25:46 +06:00
parent 22562426e7
commit c4f214758d

View File

@ -7,10 +7,7 @@ import io.ktor.client.plugins.*
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.http.* import io.ktor.http.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import java.net.Authenticator import java.net.*
import java.net.InetSocketAddress
import java.net.PasswordAuthentication
import java.net.Proxy
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -68,8 +65,12 @@ data class HttpClientConfig(
proxyConfig.password ?.toCharArray() ?: error("For Socks proxy you should use both username and password or do not use authentication at all") proxyConfig.password ?.toCharArray() ?: error("For Socks proxy you should use both username and password or do not use authentication at all")
) )
Authenticator.setDefault(object : Authenticator() { Authenticator.setDefault(object : Authenticator() {
override fun getPasswordAuthentication(): PasswordAuthentication { override fun getPasswordAuthentication(): PasswordAuthentication? {
return passwordAuthentication return if (requestingHost.lowercase() == proxyConfig.hostname.lowercase()) {
passwordAuthentication
} else {
null
}
} }
}) })
} }