Is there an HTTP request library that works both inside and outside openresty with non-blocking behaviour?

67 views
Skip to first unread message

Yan Gabriel Minário

unread,
Jul 30, 2017, 7:46:23 PM7/30/17
to openresty-en
resty.http worked very well for me so far, but I’d like to make my telegram bot library useable outside openresty, so I’d like to know if there’s such library. If not, what is the closest thing to resty.http and how to fallback properly?

Thanks.

Thibault Charbonnier

unread,
Jul 31, 2017, 1:10:57 PM7/31/17
to openre...@googlegroups.com
Hi,
I built a fallback library which, if used, will always use cosockets
where available, and fallback to LuaSocket/LuaSec where cosockets are
not available (non-supported ngx_lua contexts, or non-ngx_lua
interpreters). It was inspired by a similar module in pgmoon and
improved/externalized as an independent library here:

https://github.com/thibaultcha/lua-resty-socket

Of course, it needs to be used by the library (lua-resty-http does not
use it nor does it provide a fallback for non-supported cosocket contexts).

-- Thibault

Yan Gabriel Minário

unread,
Jul 31, 2017, 2:14:26 PM7/31/17
to openre...@googlegroups.com
In that case, I should clone resty.http and implement your library myself? I’m not sure if I’m experienced enough for that. Actually, I opened an issue asking resty.http creators to do that.

Unless your library implements luasocket/luasec.http into cosocket, in that case I could simply use that.

PS: It looks like your library is not available at opm.

Thanks for your reply!
> --
> You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/MDOIowqG_uY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to openresty-en...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Kshitij Joshi

unread,
May 4, 2021, 2:51:23 PMMay 4
to openresty-en

I have the following piece of code in the init_by_lua_file in the http context


local http = require "resty.http"

local httpc = http.newCoSocket()

where I have added


function _M.newCoSocket()

    local sock = socket.tcp() -- similar to ngx.socket.tcp(). 

    return setmetatable({. 

        sock = sock. 

    }, {__index = _M}). 

end. 

function _M:connect(host, port)

    local ok, err = self.sock:connect(host, port)

    if not ok then

        return nil, err

    end

    local times, err = self.sock:getreusedtimes() -- cosocket API

    if not times then

        return nil, err

    elseif times == 0 then

        -- handle connection

    end

end

to the http.lua file.


I get the following error on the startup


socket.lua:167: stack overflow


The line 167 is

local phase = get_phase()

Reply all
Reply to author
Forward
0 new messages