Lua socket.http sink parameter

I am trying to contact my servers from Lua for user authentication. This is what my query function looks like:

function http.send(url) local req = require("socket.http") local b, c, h = req.request{ url = url, redirect = true } return b end 

However, I noticed that the data is discarded because I did not provide the sink parameter. I want to be able to return the downloaded data as a whole line, and not load it into a file / table. How can i do this?

+4
source share
1 answer

You can use ltn12.sink.table to collect the results in a given table in parts. Then you can use table.concat to get the resulting row.

An example of using the ltn12.sink documentation:

 -- load needed modules local http = require("socket.http") local ltn12 = require("ltn12") -- a simplified http.get function function http.get(u) local t = {} local status, code, headers = http.request{ url = u, sink = ltn12.sink.table(t) } return table.concat(t), headers, code end 
+6
source

All Articles