Replace khttp with java standard library https methods
This commit is contained in:
@@ -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" }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user