summaryrefslogtreecommitdiffstats
path: root/lua/mason-core/fetch.lua
diff options
context:
space:
mode:
authorFredrik Foss-Indrehus <fredrikfoss@fr.urbanpets.no>2025-05-24 21:06:53 +0200
committerGitHub <noreply@github.com>2025-05-24 21:06:53 +0200
commit8024d64e1330b86044fed4c8494ef3dcd483a67c (patch)
treede575420b901ac5dd44221c90ac51b4e75bea370 /lua/mason-core/fetch.lua
parentdocs: rework Installation & Setup sections, and other minor adjustments (#1951) (diff)
downloadmason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar
mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.gz
mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.bz2
mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.lz
mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.xz
mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.zst
mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.zip
fix(fetch): add busybox wget support (#1829)
Co-authored-by: William Boman <william@redwill.se>
Diffstat (limited to 'lua/mason-core/fetch.lua')
-rw-r--r--lua/mason-core/fetch.lua31
1 files changed, 24 insertions, 7 deletions
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,
}