Replace khttp with java standard library https methods

This commit is contained in:
Edwin Jakobs
2020-02-28 20:57:43 +01:00
parent 75d6802ea8
commit c722a060a0
4 changed files with 15 additions and 23 deletions

View File

@@ -1,12 +1,5 @@
repositories {
maven {
url = uri("https://jitpack.io")
}
}
dependencies {
implementation "com.google.code.gson:gson:$gsonVersion"
implementation "com.github.jkcclemens:khttp:-SNAPSHOT"
implementation "org.rauschig:jarchivelib:1.0.0"
implementation project(":orx-noise")
}

View File

@@ -1,10 +1,11 @@
package org.openrndr.extra.glslify
import khttp.responses.Response
import mu.KotlinLogging
import java.io.ByteArrayInputStream
import java.io.File
import java.io.InputStream
import java.net.URL
import javax.net.ssl.HttpsURLConnection
const val BASE_URL = "https://registry.npmjs.org"
const val GLSLIFY_PATH = "src/main/resources/glslify"
@@ -35,9 +36,9 @@ fun glslify(module: String, renameFunctionTo: String? = null): String {
try {
moduleDir.mkdirs()
val response: Response = khttp.get(packageUrl, stream = true)
val tarStream: InputStream = ByteArrayInputStream(response.content)
val url = URL(packageUrl)
val con = url.openConnection()
val tarStream: InputStream = ByteArrayInputStream(con.getInputStream().readBytes())
extractGzipStream(tarStream, moduleDir)
@@ -46,6 +47,7 @@ fun glslify(module: String, renameFunctionTo: String? = null): String {
File("$moduleDir/package").deleteRecursively()
logger.trace("[glslify] $moduleName downloaded")
(con as HttpsURLConnection).disconnect()
} catch (ex: Exception) {
logger.error(ex) { "[glslify]: There was an error getting $moduleName" }

View File

@@ -2,7 +2,8 @@ package org.openrndr.extra.glslify
import com.google.gson.GsonBuilder
import com.google.gson.annotations.SerializedName
import khttp.responses.Response
import java.net.URL
import javax.net.ssl.HttpsURLConnection
internal data class NPMPackageDist(
@@ -25,20 +26,17 @@ internal data class NPMResponse(
)
internal fun getPackageUrl(module: String): String? {
val url = "$BASE_URL/$module"
val moduleUrl = "$BASE_URL/$module"
val response : Response = khttp.get(
url = url,
headers = mapOf(
"Accept" to "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8"
)
)
val url = URL(moduleUrl)
val con = url.openConnection() as HttpsURLConnection
con.setRequestProperty("Accept", "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8")
val json = String(con.inputStream.readAllBytes())
val gson = GsonBuilder().create()
val npmResponse = gson.fromJson(
response.text, NPMResponse::class.java
)
val npmResponse = gson.fromJson(json, NPMResponse::class.java)
if (npmResponse.error != null) {
return null