From e870a6a123f92b44a747304d4634b8b0fb799cc5 Mon Sep 17 00:00:00 2001 From: "Arthur K." Date: Tue, 27 Jan 2026 15:40:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B7=D0=B0:=20=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=87=D1=8C=D1=82=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=87=D0=B8=D1=82=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D1=80=20=D1=82=D0=B5=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/proxy/main.go b/proxy/main.go index 7d01449..7578dca 100644 --- a/proxy/main.go +++ b/proxy/main.go @@ -13,6 +13,8 @@ import ( "strings" ) +const MAX_SIZE = 1 << 16 // 65kb + func main() { proxy := &httputil.ReverseProxy{ Rewrite: func(r *httputil.ProxyRequest) { @@ -38,17 +40,18 @@ func main() { // Read response body into data. If body is encoded, decode it. var data []byte - switch r.Header.Get("Content-Encoding") { case "gzip": reader, _ := gzip.NewReader(r.Body) - data, _ = io.ReadAll(reader) - r.Body.Close() + data, _ = io.ReadAll(io.LimitReader(reader, MAX_SIZE)) + reader.Close() default: - data, _ = io.ReadAll(r.Body) - r.Body.Close() + data, _ = io.ReadAll(io.LimitReader(r.Body, MAX_SIZE)) } + io.Copy(io.Discard, r.Body) + r.Body.Close() + // Rewrite 30x redirect location locHeader := r.Header.Get("Location") if locHeader != "" {