Skip to content

Commit 72c1375

Browse files
committed
fix: mark keepalive_ready if no body and no trailer
1 parent 6d60978 commit 72c1375

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/resty/http.lua

+5
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,11 @@ function _M.read_response(self, params)
855855

856856
body_reader, err = _body_reader(body_reader_keepalive_ready_callback, sock, length)
857857
end
858+
else
859+
if not has_trailer then
860+
-- If there's no body and no trailer - it's ready for keep-alive
861+
self.keepalive_ready = true
862+
end
858863
end
859864

860865
if has_trailer then

t/07-keepalive.t

+45
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,48 @@ response not fully read
601601
--- no_error_log
602602
[error]
603603
[warn]
604+
605+
=== TEST 12 pool_only_after_response is on. Test the connection is reused on non-body requests.
606+
--- http_config eval: $::HttpConfig
607+
--- config
608+
location = /a {
609+
content_by_lua '
610+
local http = require "resty.http"
611+
local httpc = http.new()
612+
httpc:connect({
613+
scheme = "http",
614+
host = "127.0.0.1",
615+
port = ngx.var.server_port,
616+
pool_only_after_response = true
617+
})
618+
619+
local res, err = httpc:request{
620+
method = "HEAD",
621+
path = "/b"
622+
}
623+
624+
ngx.say(res.headers["Connection"])
625+
ngx.say(httpc:set_keepalive())
626+
627+
httpc:connect({
628+
scheme = "http",
629+
host = "127.0.0.1",
630+
port = ngx.var.server_port
631+
})
632+
ngx.say(httpc:get_reused_times())
633+
';
634+
}
635+
location = /b {
636+
content_by_lua '
637+
ngx.say("OK")
638+
';
639+
}
640+
--- request
641+
GET /a
642+
--- response_body
643+
keep-alive
644+
1
645+
1
646+
--- no_error_log
647+
[error]
648+
[warn]

0 commit comments

Comments
 (0)