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 != "" {