Skip to content

Commit d40f5ce

Browse files
authored
feat(curl): add support for streaming responses (#472)
Add a new `stream` option (function) to specify that response data should be streamed to the `stream` function.
1 parent fa63525 commit d40f5ce

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lua/plenary/curl.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,14 @@ local request = function(specs)
252252
return args
253253
end
254254

255-
local job = J:new {
255+
local job_opts = {
256256
command = "curl",
257257
args = args,
258-
on_exit = function(j, code)
258+
}
259+
if opts.stream then
260+
job_opts.on_stdout = opts.stream
261+
else
262+
job_opts.on_exit = function(j, code)
259263
if code ~= 0 then
260264
error(
261265
string.format(
@@ -273,10 +277,11 @@ local request = function(specs)
273277
else
274278
response = output
275279
end
276-
end,
277-
}
280+
end
281+
end
282+
local job = J:new(job_opts)
278283

279-
if opts.callback then
284+
if opts.callback or opts.stream then
280285
return job:start()
281286
else
282287
local timeout = opts.timeout or 10000

0 commit comments

Comments
 (0)