From 124b87b8517b2fefe1a9486f7f2f12b91d6d1ea9 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Tue, 12 Jul 2016 15:50:13 +0530 Subject: Add test for body (~b) --- mitmproxy/filt.py | 22 ++++++++++++++++------ test/mitmproxy/test_filt.py | 7 +++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mitmproxy/filt.py b/mitmproxy/filt.py index b1b72aa7..cb49283d 100644 --- a/mitmproxy/filt.py +++ b/mitmproxy/filt.py @@ -193,12 +193,22 @@ class FBod(_Rex): help = "Body" def __call__(self, f): - if f.request and f.request.content: - if self.re.search(f.request.get_decoded_content()): - return True - if f.response and f.response.content: - if self.re.search(f.response.get_decoded_content()): - return True + + # HTTPFlow + if hasattr(f, 'request'): + if f.request and f.request.content: + if self.re.search(f.request.get_decoded_content()): + return True + if f.response and f.response.content: + if self.re.search(f.response.get_decoded_content()): + return True + + # TCPFlow + elif hasattr(f, 'messages'): + for msg in f.messages: + if self.re.search(msg.content): + return True + return False diff --git a/test/mitmproxy/test_filt.py b/test/mitmproxy/test_filt.py index f6c08c67..5f3622e9 100644 --- a/test/mitmproxy/test_filt.py +++ b/test/mitmproxy/test_filt.py @@ -262,6 +262,13 @@ class TestMatchingTCPFlow: e = self.err() assert self.q("~e", e) + def test_body(self): + f = self.flow() + assert not self.q("~b nonexistent", f) + assert self.q("~b hello", f) + assert self.q("~b me", f) + + @patch('traceback.extract_tb') def test_pyparsing_bug(extract_tb): """https://github.com/mitmproxy/mitmproxy/issues/1087""" -- cgit v1.2.3