From fb9bb22d97b2139d7a31ab5debe866546a9d0e67 Mon Sep 17 00:00:00 2001 From: liqiang <974923609@qq.com> Date: Sat, 20 Feb 2021 15:20:23 +0800 Subject: [PATCH] optimize web addon content-length showing --- addon/web/client/src/utils.js | 10 ++++++++-- addon/web/message.go | 3 ++- cmd/mitmproxy/main.go | 1 - 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/addon/web/client/src/utils.js b/addon/web/client/src/utils.js index fb50dc9..10109a1 100644 --- a/addon/web/client/src/utils.js +++ b/addon/web/client/src/utils.js @@ -9,8 +9,14 @@ export const isTextResponse = response => { export const getSize = response => { if (!response) return '0' if (!response.header) return '0' - if (!response.header['Content-Length']) return '0' - const len = parseInt(response.header['Content-Length'][0]) + + let len + if (response.header['Content-Length']) { + len = parseInt(response.header['Content-Length'][0]) + } else if (response && response.body) { + len = response.body.byteLength + } + if (!len) return '0' if (isNaN(len)) return '0' if (len <= 0) return '0' diff --git a/addon/web/message.go b/addon/web/message.go index 9022c4f..c90c773 100644 --- a/addon/web/message.go +++ b/addon/web/message.go @@ -81,7 +81,8 @@ func newMessageResponse(f *flow.Flow) *message { } func newMessageResponseBody(f *flow.Flow) *message { - return newMessage(messageTypeResponseBody, f.Id, f.Response.Body) + body, _ := f.Response.DecodedBody() + return newMessage(messageTypeResponseBody, f.Id, body) } func (m *message) bytes() []byte { diff --git a/cmd/mitmproxy/main.go b/cmd/mitmproxy/main.go index 020ec1b..eba9b76 100644 --- a/cmd/mitmproxy/main.go +++ b/cmd/mitmproxy/main.go @@ -54,7 +54,6 @@ func main() { p.AddAddon(dumper) } - p.AddAddon(&addon.Decoder{}) p.AddAddon(web.NewWebAddon(config.webAddr)) log.Fatal(p.Start())