From a6e7f10d6eae95a1210d844cc67706b0bff09a50 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:34:23 -0500 Subject: [PATCH] Fix me not knowing that "" is not a number - also rc7 tiem --- build.gradle | 2 +- src/main/kotlin/mdnet/base/Application.kt | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 9bfa63e..9454f63 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = "com.mangadex" -version = "1.0.0-rc6" +version = "1.0.0-rc7" mainClassName = "mdnet.base.MangaDexClient" repositories { diff --git a/src/main/kotlin/mdnet/base/Application.kt b/src/main/kotlin/mdnet/base/Application.kt index 019eb5d..013bb92 100644 --- a/src/main/kotlin/mdnet/base/Application.kt +++ b/src/main/kotlin/mdnet/base/Application.kt @@ -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) } } }