Fix HTTP hanging and redirects
This commit is contained in:
parent
274c59f979
commit
022d170c0a
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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,15 +41,13 @@ object CachingHttpClient {
|
|||
}
|
||||
|
||||
fun getUncached(uri: URI): InputStream {
|
||||
HttpClient.newHttpClient().use {
|
||||
return it.send(
|
||||
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 {
|
||||
val path = PhytotelmaPlugin.globalCacheDir.resolve("httpCache")
|
||||
|
|
Loading…
Reference in a new issue