From 9efaef81b42622ba61bcc009edd6743a118a6001 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 226aea3..0cfb7ad 100644 --- a/lib/resty/http.lua +++ b/lib/resty/http.lua @@ -538,6 +538,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 80f003ebcd206ca928a31f6b8a2b2029a13a979a 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 0cfb7ad..dc0d292 100644 --- a/lib/resty/http.lua +++ b/lib/resty/http.lua @@ -540,8 +540,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