We don't want to overread in case a broken HTTP backend
sends us excessive data.
---
lib/yahns/proxy_http_response.rb | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index 7df2834..d4a3dda 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -146,6 +146,12 @@ def proxy_res_headers(res, req_res)
have_body
end
+ def read_len(len)
+ max = 0x2000
+ max = len if len && len < max
+ max
+ end
+
def proxy_read_body(tip, kcar, req_res)
chunk = ''.dup if kcar.chunked?
len = kcar.body_bytes_left
@@ -153,7 +159,7 @@ def proxy_read_body(tip, kcar, req_res)
alive = req_res.alive
wbuf = req_res.resbuf
- case tmp = tip.shift || req_res.kgio_tryread(0x2000, rbuf)
+ case tmp = tip.shift || req_res.kgio_tryread(read_len(len), rbuf)
when String
if len
kcar.body_bytes_left -= tmp.size # progress for body_eof? => true