Skip to content

Commit 0d66015

Browse files
authored
fix: curl args parsing (#334)
1 parent 14dfb40 commit 0d66015

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

lua/plenary/curl.lua

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,30 @@ parse.request = function(opts)
191191
opts.raw_body = b
192192
end
193193
end
194-
return vim.tbl_flatten {
195-
"-sSL",
196-
opts.dump,
197-
opts.compressed and "--compressed" or nil,
198-
parse.method(opts.method),
199-
parse.headers(opts.headers),
200-
parse.accept_header(opts.accept),
201-
parse.raw_body(opts.raw_body),
202-
parse.data_body(opts.data),
203-
parse.form(opts.form),
204-
parse.file(opts.in_file),
205-
parse.auth(opts.auth),
206-
opts.raw,
207-
opts.output and { "-o", opts.output } or nil,
208-
parse.url(opts.url, opts.query),
209-
},
210-
opts
194+
local result = { "-sSL", opts.dump }
195+
local append = function(v)
196+
if v then
197+
table.insert(result, v)
198+
end
199+
end
200+
201+
if opts.compressed then
202+
table.insert(result, "--compressed")
203+
end
204+
append(parse.method(opts.method))
205+
append(parse.headers(opts.headers))
206+
append(parse.accept_header(opts.accept))
207+
append(parse.raw_body(opts.raw_body))
208+
append(parse.data_body(opts.data))
209+
append(parse.form(opts.form))
210+
append(parse.file(opts.in_file))
211+
append(parse.auth(opts.auth))
212+
append(opts.raw)
213+
if opts.output then
214+
table.insert(result, { "-o", opts.output })
215+
end
216+
table.insert(result, parse.url(opts.url, opts.query))
217+
return vim.tbl_flatten(result), opts
211218
end
212219

213220
-- Parse response ------------------------------------------

0 commit comments

Comments
 (0)