Fix HTTP hanging and redirects

This commit is contained in:
TheKodeToad 2024-09-04 20:41:45 +01:00
parent 274c59f979
commit a625dc1275
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
2 changed files with 11 additions and 10 deletions

View file

@ -7,7 +7,7 @@ plugins {
}
group = "dev.frogmc"
version = "0.0.1-alpha.24"
version = "aaa"
repositories {
maven {
@ -46,7 +46,8 @@ gradlePlugin {
tasks.jar {
manifest {
attributes("Implementation-Version" to version,
attributes(
"Implementation-Version" to version,
"Implementation-Date" to Date(),
"Implementation-Name" to project.name
)

View file

@ -17,6 +17,8 @@ import kotlin.io.path.notExists
object CachingHttpClient {
private val CLIENT = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build()
fun downloadTo(uri: URI, path: Path, allowOverwrite: Boolean) {
if (allowOverwrite || path.notExists()) {
path.createParentDirectories()
@ -39,14 +41,12 @@ object CachingHttpClient {
}
fun getUncached(uri: URI): InputStream {
HttpClient.newHttpClient().use {
return it.send(
HttpRequest.newBuilder().uri(uri).header(
"User-Agent",
"FrogMC Phytotelma/" + CachingHttpClient.javaClass.`package`.implementationVersion
).build(), BodyHandlers.ofInputStream()
).body()
}
return CLIENT.send(
HttpRequest.newBuilder().uri(uri).header(
"User-Agent",
"FrogMC Phytotelma/" + CachingHttpClient.javaClass.`package`.implementationVersion
).build(), BodyHandlers.ofInputStream()
).body()
}
private fun getCacheFile(uri: URI): Path {