Skip to content

Commit 7feec2e

Browse files
committed
feat: convert coroutines to closures, remove unnecessary duplicate call to closures if there are trailers
1 parent 2d4feca commit 7feec2e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/resty/http.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,13 @@ _M.transfer_encoding_is_chunked = transfer_encoding_is_chunked
436436

437437

438438
local function _reader_keepalive_ready_mark(http_client)
439-
return co_wrap(function()
439+
return function()
440440
http_client.keepalive_ready = true
441-
end)
441+
end
442442
end
443443

444444
local function _reader_keepalive_ready_no_op()
445-
return co_wrap(function() end)
445+
return function() end
446446
end
447447

448448

@@ -830,13 +830,15 @@ function _M.read_response(self, params)
830830
local trailer_reader
831831
local has_body = false
832832
local has_trailer = false
833-
-- If there are no trailers - fully reading response body means socket is ready to be pooled
834-
local body_reader_keepalive_ready_callback = _reader_keepalive_ready_mark(self)
833+
local body_reader_keepalive_ready_callback
835834

836835
if res_headers["Trailer"] then
837836
has_trailer = true
838837
-- If there are trailers - fully reading response body doesn't mean socket is ready to be pooled
839838
body_reader_keepalive_ready_callback = _reader_keepalive_ready_no_op()
839+
else
840+
-- If there are no trailers - fully reading response body means socket is ready to be pooled
841+
body_reader_keepalive_ready_callback = _reader_keepalive_ready_mark(self)
840842
end
841843

842844
-- Receive the body_reader

0 commit comments

Comments
 (0)