about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <bofh@yhbt.net>2022-12-22 09:02:09 +0000
committerEric Wong <e@yhbt.net>2022-12-22 09:02:48 +0000
commite263cc5a5771dfdeb6811f812d8b054e5404621f (patch)
tree0c6b8eedd15ba5cea3b68d1c247f48b26554e276
parent89c798d2b42d43edfbf37a57f0ab13a6060ac963 (diff)
downloadyahns-e263cc5a5771dfdeb6811f812d8b054e5404621f.tar.gz
We don't want to overread in case a broken HTTP backend
sends us excessive data.
-rw-r--r--lib/yahns/proxy_http_response.rb8
1 files changed, 7 insertions, 1 deletions
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 @@ module Yahns::HttpResponse # :nodoc:
     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 @@ module Yahns::HttpResponse # :nodoc:
     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