Skip to content

Commit 91935c4

Browse files
committed
feat: remove optional flag pool_only_after_response, its always on
1 parent 7feec2e commit 91935c4

File tree

4 files changed

+10
-65
lines changed

4 files changed

+10
-65
lines changed

Diff for: README.md

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ The options table has the following fields:
171171
* `pool`: custom connection pool name. Option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect), except that the default will become a pool name constructed using the SSL / proxy properties, which is important for safe connection reuse. When in doubt, leave it blank!
172172
* `pool_size`: option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect)
173173
* `backlog`: option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect)
174-
* `pool_only_after_response`: when enabled, set_keepalive() verifies http response fully read before pooling. Default is `false`
175174
* `proxy_opts`: sub-table, defaults to the global proxy options set, see [set\_proxy\_options](#set_proxy_options).
176175
* `ssl_reused_session`: option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake)
177176
* `ssl_verify`: option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake), except that it defaults to `true`.

Diff for: lib/resty/http.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function _M.new(_)
135135
return nil, err
136136
end
137137
return setmetatable({
138-
sock = sock, keepalive_supported = true, keepalive_ready = false, pool_only_after_response = false
138+
sock = sock, keepalive_supported = true, keepalive_ready = false
139139
}, mt)
140140
end
141141

@@ -211,7 +211,7 @@ function _M.set_keepalive(self, ...)
211211
end
212212

213213
if self.keepalive_supported == true then
214-
if self.pool_only_after_response and not self.keepalive_ready then
214+
if not self.keepalive_ready then
215215
return nil, "response not fully read"
216216
end
217217

Diff for: lib/resty/http_connect.lua

-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ client:connect {
2222
pool = nil, -- connection pool name, leave blank! this function knows best!
2323
pool_size = nil, -- options as per: https://github.com/openresty/lua-nginx-module#tcpsockconnect
2424
backlog = nil,
25-
pool_only_after_response = false, -- set_keepalive() verifies http response fully read before pooling
2625
2726
-- ssl options as per: https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake
2827
ssl_reused_session = nil
@@ -61,7 +60,6 @@ local function connect(self, options)
6160

6261
local poolname = options.pool
6362
local pool_size = options.pool_size
64-
local pool_only_after_response = options.pool_only_after_response
6563
local backlog = options.backlog
6664

6765
if request_scheme and not request_port then
@@ -270,7 +268,6 @@ local function connect(self, options)
270268
-- set only for http, https has already been handled
271269
self.http_proxy_auth = request_scheme ~= "https" and proxy_authorization or nil
272270
self.path_prefix = path_prefix
273-
self.pool_only_after_response = pool_only_after_response
274271

275272
return true, nil, ssl_session
276273
end

Diff for: t/07-keepalive.t

+8-59
Original file line numberDiff line numberDiff line change
@@ -433,65 +433,18 @@ connection must be closed
433433
[error]
434434
[warn]
435435

436-
=== TEST 8 Generic interface, Connection: Keep-alive. pool_only_after_response is on. Test the connection is reused.
436+
=== TEST 8 Generic interface, Connection: Keep-alive. Don't read body and check connection isn't reused
437437
--- http_config eval: $::HttpConfig
438438
--- config
439439
location = /a {
440440
content_by_lua '
441441
local http = require "resty.http"
442442
local httpc = http.new()
443-
httpc:connect({
444-
scheme = "http",
445-
host = "127.0.0.1",
446-
port = ngx.var.server_port,
447-
pool_only_after_response = true
448-
})
449-
450-
local res, err = httpc:request{
451-
path = "/b"
452-
}
453-
454-
local body = res:read_body()
455-
456-
ngx.say(res.headers["Connection"])
457-
ngx.say(httpc:set_keepalive())
458-
459443
httpc:connect({
460444
scheme = "http",
461445
host = "127.0.0.1",
462446
port = ngx.var.server_port
463447
})
464-
ngx.say(httpc:get_reused_times())
465-
';
466-
}
467-
location = /b {
468-
content_by_lua '
469-
ngx.say("OK")
470-
';
471-
}
472-
--- request
473-
GET /a
474-
--- response_body
475-
keep-alive
476-
1
477-
1
478-
--- no_error_log
479-
[error]
480-
[warn]
481-
482-
=== TEST 9 Generic interface, Connection: Keep-alive. pool_only_after_response is on. Don't read body and check connection isn't reused
483-
--- http_config eval: $::HttpConfig
484-
--- config
485-
location = /a {
486-
content_by_lua '
487-
local http = require "resty.http"
488-
local httpc = http.new()
489-
httpc:connect({
490-
scheme = "http",
491-
host = "127.0.0.1",
492-
port = ngx.var.server_port,
493-
pool_only_after_response = true
494-
})
495448
496449
local res, err = httpc:request{
497450
path = "/b"
@@ -524,7 +477,7 @@ response not fully read
524477
[error]
525478
[warn]
526479

527-
=== TEST 10 Pooling connection immediately after connecting should work
480+
=== TEST 9 Pooling connection immediately after connecting should work
528481
--- http_config eval: $::HttpConfig
529482
--- config
530483
location = /a {
@@ -534,8 +487,7 @@ response not fully read
534487
httpc:connect({
535488
scheme = "http",
536489
host = "127.0.0.1",
537-
port = ngx.var.server_port,
538-
pool_only_after_response = true
490+
port = ngx.var.server_port
539491
})
540492
ngx.say(httpc:set_keepalive())
541493
';
@@ -548,7 +500,7 @@ GET /a
548500
[error]
549501
[warn]
550502

551-
=== TEST 11 Reusing client still checks pooling is ready
503+
=== TEST 10 Reused client still checks pooling is ready
552504
--- http_config eval: $::HttpConfig
553505
--- config
554506
location = /a {
@@ -558,8 +510,7 @@ GET /a
558510
httpc:connect({
559511
scheme = "http",
560512
host = "127.0.0.1",
561-
port = ngx.var.server_port,
562-
pool_only_after_response = true
513+
port = ngx.var.server_port
563514
})
564515
565516
local res, err = httpc:request{
@@ -574,8 +525,7 @@ GET /a
574525
httpc:connect({
575526
scheme = "http",
576527
host = "127.0.0.1",
577-
port = ngx.var.server_port,
578-
pool_only_after_response = true
528+
port = ngx.var.server_port
579529
})
580530
ngx.say(httpc:get_reused_times())
581531
res, err = httpc:request{
@@ -602,7 +552,7 @@ response not fully read
602552
[error]
603553
[warn]
604554

605-
=== TEST 12 pool_only_after_response is on. Test the connection is reused on non-body requests.
555+
=== TEST 11 Test the connection is reused on non-body requests
606556
--- http_config eval: $::HttpConfig
607557
--- config
608558
location = /a {
@@ -612,8 +562,7 @@ response not fully read
612562
httpc:connect({
613563
scheme = "http",
614564
host = "127.0.0.1",
615-
port = ngx.var.server_port,
616-
pool_only_after_response = true
565+
port = ngx.var.server_port
617566
})
618567
619568
local res, err = httpc:request{

0 commit comments

Comments
 (0)