Compare commits
2 commits
274c59f979
...
18143913b8
Author | SHA1 | Date | |
---|---|---|---|
TheKodeToad | 18143913b8 | ||
TheKodeToad | 022d170c0a |
|
@ -46,7 +46,8 @@ gradlePlugin {
|
||||||
|
|
||||||
tasks.jar {
|
tasks.jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes("Implementation-Version" to version,
|
attributes(
|
||||||
|
"Implementation-Version" to version,
|
||||||
"Implementation-Date" to Date(),
|
"Implementation-Date" to Date(),
|
||||||
"Implementation-Name" to project.name
|
"Implementation-Name" to project.name
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,6 +17,8 @@ import kotlin.io.path.notExists
|
||||||
|
|
||||||
object CachingHttpClient {
|
object CachingHttpClient {
|
||||||
|
|
||||||
|
private val CLIENT = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build()
|
||||||
|
|
||||||
fun downloadTo(uri: URI, path: Path, allowOverwrite: Boolean) {
|
fun downloadTo(uri: URI, path: Path, allowOverwrite: Boolean) {
|
||||||
if (allowOverwrite || path.notExists()) {
|
if (allowOverwrite || path.notExists()) {
|
||||||
path.createParentDirectories()
|
path.createParentDirectories()
|
||||||
|
@ -39,14 +41,12 @@ object CachingHttpClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUncached(uri: URI): InputStream {
|
fun getUncached(uri: URI): InputStream {
|
||||||
HttpClient.newHttpClient().use {
|
return CLIENT.send(
|
||||||
return it.send(
|
HttpRequest.newBuilder().uri(uri).header(
|
||||||
HttpRequest.newBuilder().uri(uri).header(
|
"User-Agent",
|
||||||
"User-Agent",
|
"FrogMC Phytotelma/" + CachingHttpClient.javaClass.`package`.implementationVersion
|
||||||
"FrogMC Phytotelma/" + CachingHttpClient.javaClass.`package`.implementationVersion
|
).build(), BodyHandlers.ofInputStream()
|
||||||
).build(), BodyHandlers.ofInputStream()
|
).body()
|
||||||
).body()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCacheFile(uri: URI): Path {
|
private fun getCacheFile(uri: URI): Path {
|
||||||
|
|
Loading…
Reference in a new issue