Fix me not knowing that "" is not a number - also rc7 tiem

This commit is contained in:
carbotaniuman 2020-06-08 20:34:23 -05:00
parent 907e90803d
commit a6e7f10d6e
2 changed files with 16 additions and 6 deletions

View file

@ -7,7 +7,7 @@ plugins {
}
group = "com.mangadex"
version = "1.0.0-rc6"
version = "1.0.0-rc7"
mainClassName = "mdnet.base.MangaDexClient"
repositories {

View file

@ -71,17 +71,27 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
statistics.get().requestsServed.incrementAndGet()
// Netty doesn't do Content-Length or Content-Type, so we have the pleasure of doing that ourselves
fun respondWithImage(input: InputStream, length: String, type: String, lastModified: String): Response =
Response(Status.OK).header("Content-Length", length)
fun respondWithImage(input: InputStream, length: String?, type: String, lastModified: String?): Response =
Response(Status.OK)
.header("Content-Type", type)
.header("X-Content-Type-Options", "nosniff")
.header("Last-Modified", lastModified)
.header(
"Cache-Control",
listOf("public", MaxAgeTtl(Constants.MAX_AGE_CACHE).toHeaderValue()).joinToString(", ")
)
.header("Timing-Allow-Origin", "https://mangadex.org")
.body(input, length.toLong())
.also {
if(length != null) {
it.body(input, length.toLong())
it.header("Content-Length", length)
} else {
it.body(input)
}
if(lastModified != null) {
it.header("Last-Modified", lastModified)
}
}
val snapshot = cache.get(cacheId)
if (snapshot != null) {
@ -169,7 +179,7 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
LOGGER.trace("Request for ${request.uri} is being served")
}
respondWithImage(mdResponse.body.stream, contentLength ?: "", contentType, lastModified ?: "")
respondWithImage(mdResponse.body.stream, contentLength, contentType, lastModified)
}
}
}