From 8311216a2cc151a937609a951aed30c13c598e9c Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 18 Mar 2024 14:21:50 +0100 Subject: [PATCH 1/2] fix(body-reader): do not call sock:receive for reading 0 bytes Some sockets can block if called to read 0 bytes until actual bytes are available to read. --- lib/resty/http.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/resty/http.lua b/lib/resty/http.lua index a85f85a..4bf49f2 100644 --- a/lib/resty/http.lua +++ b/lib/resty/http.lua @@ -522,6 +522,9 @@ local function _body_reader(sock, content_length, default_chunk_size) elseif not max_chunk_size then -- We have a length and potentially keep-alive, but want everything. + if content_length == 0 then + co_yield("") + end co_yield(sock:receive(content_length)) else From 02ccc047b24779d1c96e27eacd2823e7296b7ec1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 21 May 2024 11:07:01 +0200 Subject: [PATCH 2/2] fix: yield doesn't return, so needs an `else` --- lib/resty/http.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/resty/http.lua b/lib/resty/http.lua index 4bf49f2..3071863 100644 --- a/lib/resty/http.lua +++ b/lib/resty/http.lua @@ -524,8 +524,9 @@ local function _body_reader(sock, content_length, default_chunk_size) -- We have a length and potentially keep-alive, but want everything. if content_length == 0 then co_yield("") + else + co_yield(sock:receive(content_length)) end - co_yield(sock:receive(content_length)) else -- We have a length and potentially a keep-alive, and wish to stream