Question request POST In lua

I apologize if the question does not concern Jitsi meet

I send post request with lua prosody everything works fine with my dev api when I changed the url for the prod api version nothing works though ok on postman

here is the way I use it

local function async_http_request(url, options, callback, timeout_callback, retries)
options.insecure = true;
local completed = false;
local timed_out = false;
local retries = retries or api_retry_count;

local function cb_(response_body, response_code)
    if not timed_out then  -- request completed before timeout
        completed = true;
        if (response_code == 0 or api_should_retry_for_code(response_code)) and retries > 0 then
            module:log("warn", "API Response code %d. Will retry after %ds", response_code, api_retry_delay);
            timer.add_task(api_retry_delay, function()
                async_http_request(url, options, callback, timeout_callback, retries - 1)

        module:log("debug", "%s %s returned code %s", options.method, url, response_code);

        if callback then
            callback(response_body, response_code)

local request = http.request(url, options, cb_);

timer.add_task(api_timeout, function ()
    timed_out = true;

    if not completed then
        if timeout_callback then


and this my error in prosody.log

May 27 15:05:02 timer error Traceback[timer]: …itsi-meet/prosody-plugins/mod_speakerstats_component.lua:212: attempt to call field ‘destroy_request’ (a nil value)
stack traceback:
…itsi-meet/prosody-plugins/mod_speakerstats_component.lua:212: in function <…itsi-meet/prosody-plugins/mod_speakerstats_component.lua:208>
[C]: in function ‘xpcall’
/usr/lib/prosody/util/timer.lua:39: in function ‘callback’
/usr/lib/prosody/net/server_event.lua:831: in function </usr/lib/prosody/net/server_event.lua:830>
[C]: in function ‘loop’
/usr/lib/prosody/net/server_event.lua:763: in function </usr/lib/prosody/net/server_event.lua:762>
[C]: in function ‘xpcall’
/usr/bin/prosody:80: in function ‘loop’
/usr/bin/prosody:90: in main chunk
[C]: in ?

line 212 : http.destroy_request(request);
line 208 : timer.add_task(api_timeout, function ()

and this my request

async_http_request(‘https://myurl’, {
method = “POST”;
headers = {
[“User-Agent”] = “Prosody (”…prosody.version…"; “…prosody.platform…”)";
[“Content-Type”] = “application/json”;
[“Authorization”] = “Bearer token”;

                 body = json.encode({
                     ['test'] = "test" ,
                      ['test'] = "test" ,

all work fine if juste i change https://myurl with url of dev

any help please


Is the dev URL also https?

Can you post the same request by curl on jitsi server?


The 2 url with https, if i pass a curl from jitsi serve it s work fine


When i do a module log to get more information th request don’t even enter here, the function cb_ not called

local function cb_(response_body, response_code)


That looks suspicious. What does the import for http look like?

local http = require “net.http”;


Looks correct. And nothing is overriding the http variable, yes?

I suspect the reason you’re not seeing _cb being called is because the request has not completed when api_timeout expired and the function triggered by the timer is crashing because http.destroy_request does not exist.

And when you were pointing at your dev server, the request completed before the timeout and so the if not completed branch is not entered and you don’t see the crash.

So you have at least 2 things to figure out here:

  1. Why is the call to prod API not responding before api_timeout? What happens if you set a much bigger timeout?
  2. Why does http.destroy_request not exist?

Also, what version of prosody are you using?

net.http.destroy_request was (accidentally) removed in prosody version 0.11.0 and this was restored in 0.11.16. So if you’re using 0.11.0-0.11.5, you might want to upgrade prosody, or to stick to same prosody version do something like this:

apt list -a prosody
Listing… Done
prosody/oldstable,now 0.11.2-1+deb10u4 amd64 [installed,automatic]

Yup. That’s it. Your version of prosody does not have http.destroy_request.

You can address that short term by not calling that if the method does not exist (see code I quoted above), but long term you probably want to consider upgrading prosody. You should be able to get 0.12.x if you add the prosody package repo.

i have this in my lib lua

if http.destroy_request ~= nil then

The problem is not with util.lib.lua but with your code calling http.destroy_request when your version of prosody does not expose that function. The util.lib.lua code is an example of how to make you code work even without that method.

if i upgrade prosody i will lose my configuration with jitsi or jibri ?

My guess is no, but I don’t know. I always rebuild new instances instead of upgrade to avoid complications, so I have no experience with upgrading and what issues it might cause.

Someone else might be able to offer you better advice on that.

ok thank you for your help

since i put this in async function

if http.destroy_request ~= nil then

but not working

What do you mean by “not working”? Is it still failing with the same error?

If you no longer see that error, then you’ve solved one problem but you still have to work out why your API calls to your prod API is timing out. And I’m afraid debugging your API is beyond the scope of what I can currently assist with.

Perhaps consider:

  1. adding logging in your timeout handler to confirm that the API call is indeed timing out
  2. Increasing api_timeout to something large to confirm if it it is just slow or stalling somewhere.
  3. You mentioned curl works fine with your API – what options did you use? Did you use the same headers you’re passing in from prosody? Did the call take long?

Thank you for your time
this a log for my call api

May 27 21:52:37 http debug Making HTTPS POST request ‘5648dbf38cc0’ to https://api-prod/meet/
May 27 21:52:37 net.connect debug [pending connection 5RoEvMuy] Starting connection process
May 27 21:52:37 net.connect debug [pending connection 5RoEvMuy] Checking for targets…
May 27 21:52:37 adns debug Records for api-prod not in cache, sending query (thread: 0x5648dbefeeb0)…
May 27 21:52:37 adns debug Sending DNS query to 2001:bc8:401::3
May 27 21:52:37 adns debug Records for api-prod not in cache, sending query (thread: 0x5648dbf03a70)…
May 27 21:52:37 adns debug Sending DNS query to 2001:bc8:401::3

May 27 21:52:37 adns debug Reply for api-prod (thread: 0x5648dbefeeb0)
May 27 21:52:37 adns debug Reply for api-prod (thread: 0x5648dbf03a70)