From 1a8d2c9337cfe42caede8d3b9f4ce66e4295297e Mon Sep 17 00:00:00 2001 From: Faur Ioan-Aurel Date: Wed, 3 Sep 2025 01:01:47 +0300 Subject: [PATCH] fix: relaxed Content-Type checks for cli download This PR fixes download failure for Windows .exe binaries by relaxing strict Content-Type checks. Previously, the plugin only accepted application/octet-stream, causing failures when .exe files were served as application/x-msdos-executable by some servers. - resolves #187 --- CHANGELOG.md | 1 + .../toolbox/cli/downloader/CoderDownloadService.kt | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8358d75..404d50e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixed - NPE during error reporting +- relaxed `Content-Type` checks while downloading the CLI ## 0.6.3 - 2025-08-25 diff --git a/src/main/kotlin/com/coder/toolbox/cli/downloader/CoderDownloadService.kt b/src/main/kotlin/com/coder/toolbox/cli/downloader/CoderDownloadService.kt index 574184c..468bfd8 100644 --- a/src/main/kotlin/com/coder/toolbox/cli/downloader/CoderDownloadService.kt +++ b/src/main/kotlin/com/coder/toolbox/cli/downloader/CoderDownloadService.kt @@ -25,6 +25,18 @@ import java.util.zip.GZIPInputStream import kotlin.io.path.name import kotlin.io.path.notExists +private val SUPPORTED_BIN_MIME_TYPES = listOf( + "application/octet-stream", + "application/exe", + "application/dos-exe", + "application/msdos-windows", + "application/x-exe", + "application/x-msdownload", + "application/x-winexe", + "application/x-msdos-program", + "application/x-msdos-executable", + "application/vnd.microsoft.portable-executable" +) /** * Handles the download steps of Coder CLI */ @@ -52,7 +64,7 @@ class CoderDownloadService( return when (response.code()) { HTTP_OK -> { val contentType = response.headers()["Content-Type"]?.lowercase() - if (contentType?.startsWith("application/octet-stream") != true) { + if (contentType !in SUPPORTED_BIN_MIME_TYPES) { throw ResponseException( "Invalid content type '$contentType' when downloading CLI from $remoteBinaryURL. Expected application/octet-stream.", response.code()