Skip to content

Commit

Permalink
Kotlin#213 obtain proxy settings from JVM arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jAwAno committed Jun 6, 2018
1 parent e94df7b commit 3a0fc31
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.parents
import java.io.ByteArrayOutputStream
import java.io.PrintWriter
import java.net.HttpURLConnection
import java.net.URL
import java.net.URLConnection
import java.net.*
import java.nio.file.Path
import java.security.MessageDigest

Expand All @@ -42,7 +40,26 @@ class ExternalDocumentationLinkResolver @Inject constructor(
val cachedProtocols = setOf("http", "https", "ftp")

fun URL.doOpenConnectionToReadContent(timeout: Int = 10000, redirectsAllowed: Int = 16): URLConnection {
val connection = this.openConnection()

val proxyHost: String? = System.getProperty("http.proxyHost")
val proxyPort: String? = System.getProperty("http.proxyPort")

val connection = if(proxyHost != null && proxyPort != null){
val proxyUser: String? = System.getProperty("http.proxyUser")
val proxyPassword: String? = System.getProperty("http.proxyPassword")
if(proxyUser != null && proxyPassword != null){
Authenticator.setDefault( object : Authenticator() {
override fun getPasswordAuthentication(): PasswordAuthentication {
return PasswordAuthentication(proxyUser,proxyPassword.toCharArray())
}
})
}
this.openConnection(Proxy(Proxy.Type.HTTP,
InetSocketAddress(proxyHost,Integer.parseInt(proxyPort))))
}else{
this.openConnection()
}

connection.connectTimeout = timeout
connection.readTimeout = timeout

Expand Down

0 comments on commit 3a0fc31

Please sign in to comment.