22.02.2021, 07:21
Do not set the source if payload is not provided:
There's another issue with your code when payload or add_headers are set: ip/port variables are not set, so the function call will produce an error. You can use socket.url to parse the url into parts: http://w3.impa.br/~diego/software/luasoc...html#parse
Code:
local source
if payload then
source = ltn12.source.string(payload)
end
...
local res, err, res_headers, status = htps.request({
...
source = source, -- source will be nil if payload is not provided
...
})
There's another issue with your code when payload or add_headers are set: ip/port variables are not set, so the function call will produce an error. You can use socket.url to parse the url into parts: http://w3.impa.br/~diego/software/luasoc...html#parse