Skip to content

Commit 54b52db

Browse files
committed
Rework simple interface keepalive settings
1 parent d7c616f commit 54b52db

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,13 @@ When the request is successful, `res` will contain the following fields:
275275

276276
`syntax: res, err = httpc:request_uri(uri, params)`
277277

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:
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.
279279

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).
280+
There are 3 additional parmaters for controlling keepalives:
281+
282+
* `keepalive` Set to `false` to disable keepalives and immediately close the connection.
283+
* `keepalive_timeout` The maximal idle timeout (ms). Defaults to `lua_socket_keepalive_timeout`.
284+
* `keepalive_pool` The maxmimal number of connections in the pool. Defaults to `lua_socket_pool_size`.
282285

283286
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.
284287

lib/resty/http.lua

+8-21
Original file line numberDiff line numberDiff line change
@@ -873,31 +873,18 @@ function _M.request_uri(self, uri, params)
873873

874874
res.body = body
875875

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
882-
else
883-
if params.keepalive_timeout == -1 then
884-
ok, err = self:close()
876+
if params.keepalive == false then
877+
local ok, err = self:close()
885878
if not ok then
886879
ngx_log(ngx_ERR, err)
887880
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
881+
882+
else
883+
local ok, err = self:set_keepalive(params.keepalive_timeout, params.keepalive_pool)
884+
if not ok then
885+
ngx_log(ngx_ERR, err)
899886
end
900-
end
887+
901888
end
902889

903890
return res, nil

0 commit comments

Comments
 (0)