Skip to content

Commit

Permalink
fix: mark keepalive_ready if no body and no trailer
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyLewin committed Apr 20, 2022
1 parent 6a4075c commit 2d4feca
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/resty/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,11 @@ function _M.read_response(self, params)

body_reader, err = _body_reader(body_reader_keepalive_ready_callback, sock, length)
end
else
if not has_trailer then
-- If there's no body and no trailer - it's ready for keep-alive
self.keepalive_ready = true
end
end

if has_trailer then
Expand Down
45 changes: 45 additions & 0 deletions t/07-keepalive.t
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,48 @@ response not fully read
--- no_error_log
[error]
[warn]

=== TEST 12 pool_only_after_response is on. Test the connection is reused on non-body requests.
--- http_config eval: $::HttpConfig
--- config
location = /a {
content_by_lua '
local http = require "resty.http"
local httpc = http.new()
httpc:connect({
scheme = "http",
host = "127.0.0.1",
port = ngx.var.server_port,
pool_only_after_response = true
})

local res, err = httpc:request{
method = "HEAD",
path = "/b"
}

ngx.say(res.headers["Connection"])
ngx.say(httpc:set_keepalive())

httpc:connect({
scheme = "http",
host = "127.0.0.1",
port = ngx.var.server_port
})
ngx.say(httpc:get_reused_times())
';
}
location = /b {
content_by_lua '
ngx.say("OK")
';
}
--- request
GET /a
--- response_body
keep-alive
1
1
--- no_error_log
[error]
[warn]

0 comments on commit 2d4feca

Please sign in to comment.