From 8024d64e1330b86044fed4c8494ef3dcd483a67c Mon Sep 17 00:00:00 2001 From: Fredrik Foss-Indrehus Date: Sat, 24 May 2025 21:06:53 +0200 Subject: fix(fetch): add busybox wget support (#1829) Co-authored-by: William Boman --- lua/mason-core/fetch.lua | 31 ++++++++++++++++++++++++------- lua/mason/health.lua | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'lua') diff --git a/lua/mason-core/fetch.lua b/lua/mason-core/fetch.lua index c1f01dc2..be79db1f 100644 --- a/lua/mason-core/fetch.lua +++ b/lua/mason-core/fetch.lua @@ -75,19 +75,36 @@ local function fetch(url, opts) end local function wget() - local headers = - _.sort_by(_.identity, _.map(_.compose(_.format "--header=%s", _.join ": "), _.to_pairs(opts.headers))) + local headers = _.sort_by( + _.nth(2), + _.map( + _.compose(function(header) + return { "--header", header } + end, _.join ": "), + _.to_pairs(opts.headers) + ) + ) + + if opts.data and opts.method ~= "POST" then + return Result.failure(("fetch: data provided but method is not POST (was %s)"):format(opts.method or "-")) + end + + if not _.any(_.equals(opts.method), { "GET", "POST" }) then + -- Note: --spider can be used for HEAD support, if ever needed + return Result.failure(("fetch: wget doesn't support HTTP method %s"):format(opts.method)) + end + return spawn.wget { headers, - "-nv", "-o", "/dev/null", "-O", opts.out_file or "-", - ("--timeout=%s"):format(TIMEOUT_SECONDS), - ("--method=%s"):format(opts.method), - opts.data and { - ("--body-data=%s"):format(opts.data) or vim.NIL, + "-T", + TIMEOUT_SECONDS, + opts.data and opts.method == "POST" and { + "--post-data", + opts.data, } or vim.NIL, url, } diff --git a/lua/mason/health.lua b/lua/mason/health.lua index fcef1832..b105940d 100644 --- a/lua/mason/health.lua +++ b/lua/mason/health.lua @@ -94,7 +94,7 @@ local function check_core_utils() check { name = "unzip", cmd = "unzip", args = { "-v" }, relaxed = true } -- wget is used interchangeably with curl, but with lower priority, so we mark wget as relaxed - check { cmd = "wget", args = { "--version" }, name = "wget", relaxed = true } + check { cmd = "wget", args = { "--help" }, name = "wget", relaxed = true } check { cmd = "curl", args = { "--version" }, name = "curl" } check { cmd = "gzip", -- cgit v1.2.3-70-g09d2