From 86a84c69866395910a2850276fc76fffab365442 Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 25 May 2021 23:01:49 +0100 Subject: [PATCH] Serve .jar files with the correct MIME type Signed-off-by: Graham --- .../kotlin/org/openrs2/game/net/http/Http.kt | 3 +++ .../openrs2/game/net/http/HttpChannelHandler.kt | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/game/src/main/kotlin/org/openrs2/game/net/http/Http.kt b/game/src/main/kotlin/org/openrs2/game/net/http/Http.kt index 13b9f4af..fea1bab7 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/http/Http.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/http/Http.kt @@ -18,7 +18,10 @@ import org.openrs2.buffer.use public object Http { public const val MAX_CONTENT_LENGTH: Int = 65536 + + public const val APPLICATION_JAVA_ARCHIVE: String = "application/java-archive" public const val TEXT_X_CROSS_DOMAIN_POLICY: String = "text/x-cross-domain-policy" + private const val BANNER = "OpenRS2" private fun isKeepAlive(request: HttpRequest, version: HttpVersion): Boolean { diff --git a/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt b/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt index 7e04fe86..7fbac7fa 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt @@ -34,7 +34,21 @@ public class HttpChannelHandler @Inject constructor( return } - Http.writeResponse(ctx, msg, file, HttpHeaderValues.APPLICATION_OCTET_STREAM) + Http.writeResponse(ctx, msg, file, getContentType(uri)) + } + } + + private fun getContentType(uri: String): CharSequence { + /* + * It doesn't make sense to return a MIME type for some of the files: + * + * - The .pack200 files are missing two bytes in the header. + * - The .lib and .pack files are probably compressed with DEFLATE in + * nowrap mode. + */ + return when { + uri.endsWith(".jar") -> Http.APPLICATION_JAVA_ARCHIVE + else -> HttpHeaderValues.APPLICATION_OCTET_STREAM } }