Skip to content

Commit ec90bf7

Browse files
committed
instead of keepalive_opts
1 parent 573e192 commit ec90bf7

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ server {
6767
headers = {
6868
["Content-Type"] = "application/x-www-form-urlencoded",
6969
},
70-
keepalive_opts = {10000, 10}
70+
keepalive_timeout = 60,
71+
keepalive_pool = 10
7172
})
7273

7374
if not res then
@@ -274,7 +275,10 @@ When the request is successful, `res` will contain the following fields:
274275

275276
`syntax: res, err = httpc:request_uri(uri, params)`
276277

277-
The simple interface. Options supplied in the `params` table are the same as in the generic interface, and will override components found in the uri itself, and you can set keepalive options with `keepalive_opts`.
278+
The simple interface. Options supplied in the `params` table are the same as in the generic interface, and will override components found in the uri itself, Moreover you can set keepalive options with to fileds:
279+
280+
* `keepalive_timeout` A value for tcpsock:setkeepalive (default is 0), Set `-1` to close connection immediately.
281+
* `keepalive_pool` A value for tcpsock:setkeepalive (default is lua_socket_pool_size).
278282

279283
In this mode, there is no need to connect manually first. The connection is made on your behalf, suiting cases where you simply need to grab a URI without too much hassle.
280284

lib/resty/http.lua

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -873,21 +873,31 @@ function _M.request_uri(self, uri, params)
873873

874874
res.body = body
875875

876-
if params.keepalive_opts == nil then
877-
local ok, err = self:set_keepalive()
878-
if not ok then
879-
ngx_log(ngx_ERR, err)
880-
end
881-
elseif params.keepalive_opts == false then
882-
local ok, err = self:close()
883-
if not ok then
884-
ngx_log(ngx_ERR, err)
885-
end
876+
local ok, err
877+
if params.keepalive_timeout == nil then
878+
ok, err = self:set_keepalive()
879+
if not ok then
880+
ngx_log(ngx_ERR, err)
881+
end
886882
else
887-
local ok, err = self:set_keepalive(unpack(params.keepalive_opts))
883+
if params.keepalive_timeout == -1 then
884+
ok, err = self:close()
888885
if not ok then
889886
ngx_log(ngx_ERR, err)
890887
end
888+
else
889+
if params.keepalive_pool then
890+
ok, err = self:set_keepalive(params.keepalive_timeout, params.keepalive_pool)
891+
if not ok then
892+
ngx_log(ngx_ERR, err)
893+
end
894+
else
895+
ok, err = self:set_keepalive(params.keepalive_timeout)
896+
if not ok then
897+
ngx_log(ngx_ERR, err)
898+
end
899+
end
900+
end
891901
end
892902

893903
return res, nil

0 commit comments

Comments
 (0)