From e06ee21f3bfc7d03d9f8c0ab68b9e28822eb0952 Mon Sep 17 00:00:00 2001 From: comp500 Date: Thu, 22 Oct 2020 20:53:36 +0100 Subject: [PATCH] Add User-Agent to download requests --- .../installer/request/handlers/RequestHandlerHTTP.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/link/infra/packwiz/installer/request/handlers/RequestHandlerHTTP.kt b/src/main/kotlin/link/infra/packwiz/installer/request/handlers/RequestHandlerHTTP.kt index 3292ec8..b1ad534 100644 --- a/src/main/kotlin/link/infra/packwiz/installer/request/handlers/RequestHandlerHTTP.kt +++ b/src/main/kotlin/link/infra/packwiz/installer/request/handlers/RequestHandlerHTTP.kt @@ -4,6 +4,7 @@ import link.infra.packwiz.installer.metadata.SpaceSafeURI import link.infra.packwiz.installer.request.IRequestHandler import okio.Source import okio.source +import java.net.HttpURLConnection open class RequestHandlerHTTP : IRequestHandler { override fun matchesHandler(loc: SpaceSafeURI): Boolean { @@ -12,14 +13,17 @@ open class RequestHandlerHTTP : IRequestHandler { } override fun getFileSource(loc: SpaceSafeURI): Source? { - val conn = loc.toURL().openConnection() + val conn = loc.toURL().openConnection() as HttpURLConnection // TODO: when do we send specific headers??? should there be a way to signal this? - // github *sometimes* requires it, sometimes not! - //conn.addRequestProperty("Accept", "application/octet-stream"); + conn.addRequestProperty("Accept", "application/octet-stream") + // TODO: include version? + conn.addRequestProperty("User-Agent", "packwiz-installer") + conn.apply { // 30 second read timeout readTimeout = 30 * 1000 + requestMethod = "GET" } - return conn.getInputStream().source() + return conn.inputStream.source() } } \ No newline at end of file