aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-08-14 13:54:55 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-19 13:34:10 +0200
commit20f1a23cf97bf2d0d77c3942fda23af08479dfcc (patch)
tree9d2c7bd12cb4fd8dcaf64338782fa48e28897448 /plugins/base/src/main/kotlin
parent116fc3e188c89cc0386a97cd149da67fd695e37b (diff)
downloaddokka-20f1a23cf97bf2d0d77c3942fda23af08479dfcc.tar.gz
dokka-20f1a23cf97bf2d0d77c3942fda23af08479dfcc.tar.bz2
dokka-20f1a23cf97bf2d0d77c3942fda23af08479dfcc.zip
Rename `doOpenConnectionToReadContent` to `readContent` and make it return `InputStream`
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt4
-rw-r--r--plugins/base/src/main/kotlin/resolvers/shared/utils.kt33
2 files changed, 19 insertions, 18 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt
index a9f0e618..bf59e2ff 100644
--- a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt
+++ b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt
@@ -15,7 +15,7 @@ data class PackageList(
if (dokkaContext.configuration.offlineMode && url.protocol.toLowerCase() != "file")
return null
- val packageListStream = url.doOpenConnectionToReadContent().getInputStream()
+ val packageListStream = url.readContent()
val (params, packages) =
packageListStream
.bufferedReader()
@@ -39,4 +39,4 @@ data class PackageList(
return PackageList(format, packages.toSet(), locations, url)
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/base/src/main/kotlin/resolvers/shared/utils.kt b/plugins/base/src/main/kotlin/resolvers/shared/utils.kt
index cb737041..0c3f2495 100644
--- a/plugins/base/src/main/kotlin/resolvers/shared/utils.kt
+++ b/plugins/base/src/main/kotlin/resolvers/shared/utils.kt
@@ -1,36 +1,37 @@
package org.jetbrains.dokka.base.resolvers.shared
+import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
import java.net.URLConnection
-internal fun URL.doOpenConnectionToReadContent(timeout: Int = 10000, redirectsAllowed: Int = 16): URLConnection {
- val connection = this.openConnection().apply {
- connectTimeout = timeout
- readTimeout = timeout
- }
+internal fun URL.readContent(timeout: Int = 10000, redirectsAllowed: Int = 16): InputStream {
+ fun URL.doOpenConnection(timeout: Int, redirectsAllowed: Int): URLConnection {
+ val connection = this.openConnection().apply {
+ connectTimeout = timeout
+ readTimeout = timeout
+ }
+
+ when (connection) {
+ is HttpURLConnection -> return when (connection.responseCode) {
+ in 200..299 -> connection
- when (connection) {
- is HttpURLConnection -> {
- return when (connection.responseCode) {
- in 200..299 -> {
- connection
- }
HttpURLConnection.HTTP_MOVED_PERM,
HttpURLConnection.HTTP_MOVED_TEMP,
HttpURLConnection.HTTP_SEE_OTHER -> {
if (redirectsAllowed > 0) {
val newUrl = connection.getHeaderField("Location")
- URL(newUrl).doOpenConnectionToReadContent(timeout, redirectsAllowed - 1)
+ URL(newUrl).doOpenConnection(timeout, redirectsAllowed - 1)
} else {
throw RuntimeException("Too many redirects")
}
}
- else -> {
- throw RuntimeException("Unhandled http code: ${connection.responseCode}")
- }
+
+ else -> throw RuntimeException("Unhandled HTTP code: ${connection.responseCode}")
}
+
+ else -> return connection
}
- else -> return connection
}
+ return doOpenConnection(timeout, redirectsAllowed).getInputStream()
}