* [PATCH 2/4] http_response: clamp body read size
2022-12-22 9:02 5% [PATCH 0/4] a few forgotten patches from last year Eric Wong
@ 2022-12-22 9:02 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2022-12-22 9:02 UTC (permalink / raw)
To: yahns-public
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
^ permalink raw reply related [relevance 7%]
* [PATCH 0/4] a few forgotten patches from last year
@ 2022-12-22 9:02 5% Eric Wong
2022-12-22 9:02 7% ` [PATCH 2/4] http_response: clamp body read size Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2022-12-22 9:02 UTC (permalink / raw)
To: yahns-public
Dreading what breakage Rack 3.0 and Ruby 3.2 brings :<
Eric Wong (4):
test_buffer_tmpdir: drop fragile assertions
http_response: clamp body read size
standardize on 16384-byte reads
test/test_ssl: workaround multi-line exception messages
lib/yahns/http_client.rb | 2 +-
lib/yahns/proxy_http_response.rb | 10 ++++++++--
lib/yahns/req_res.rb | 6 +++---
test/test_buffer_tmpdir.rb | 2 --
test/test_ssl.rb | 2 +-
5 files changed, 13 insertions(+), 9 deletions(-)
^ permalink raw reply [relevance 5%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2022-12-22 9:02 5% [PATCH 0/4] a few forgotten patches from last year Eric Wong
2022-12-22 9:02 7% ` [PATCH 2/4] http_response: clamp body read size Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).