From 573723b61e90d9ab06e3c7893c6bb39941c9006c Mon Sep 17 00:00:00 2001 From: lqqyt2423 <974923609@qq.com> Date: Wed, 16 Dec 2020 11:48:17 +0800 Subject: [PATCH] add StreamLargeBodies option --- cmd/mitmproxy/main.go | 3 ++- proxy/proxy.go | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/mitmproxy/main.go b/cmd/mitmproxy/main.go index 1350928..f2f96ea 100644 --- a/cmd/mitmproxy/main.go +++ b/cmd/mitmproxy/main.go @@ -16,7 +16,8 @@ func main() { }) opts := &proxy.Options{ - Addr: ":9080", + Addr: ":9080", + StreamLargeBodies: 1024 * 1024 * 5, } p, err := proxy.NewProxy(opts) diff --git a/proxy/proxy.go b/proxy/proxy.go index 2ee1e07..2700467 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -73,14 +73,15 @@ func transfer(log *_log.Entry, a, b io.ReadWriter) { } type Options struct { - Addr string + Addr string + StreamLargeBodies int64 } type Proxy struct { Server *http.Server Client *http.Client Mitm Mitm - StreamLargeBodies int64 + StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式 Addons []flow.Addon } @@ -344,7 +345,11 @@ func NewProxy(opts *Options) (*Proxy, error) { proxy.Mitm = mitm - proxy.StreamLargeBodies = 1024 * 1024 * 5 // 5mb + if opts.StreamLargeBodies > 0 { + proxy.StreamLargeBodies = opts.StreamLargeBodies + } else { + proxy.StreamLargeBodies = 1024 * 1024 * 5 // default: 5mb + } proxy.Addons = make([]flow.Addon, 0) proxy.AddAddon(&flow.LogAddon{})