Repository: mitmproxy/mitmproxy

Issue:
Interception does not work
##### Steps to reproduce the problem:
1. `mitmproxy -i '.*'`
2. `curl -x localhost:8080 example.com`
##### What is the expected behavior?

Request should be intercepted
##### What went wrong?

Request is not intercepted.
##### Any other comments? What have you tried so far?

https://discourse.mitmproxy.org/t/is-intercept-working-in-the-head-of-master/186

---

Mitmproxy Version: master
Operating System: Win10 x64

<!-- Please use the mitmproxy forums (https://discourse.mitmproxy.org/) for support/how-to questions. Thanks! :) -->

Interception does not work
##### Steps to reproduce the problem:
1. `mitmproxy -i '.*'`
2. `curl -x localhost:8080 example.com`
##### What is the expected behavior?

Request should be intercepted
##### What went wrong?

Request is not intercepted.
##### Any other comments? What have you tried so far?

https://discourse.mitmproxy.org/t/is-intercept-working-in-the-head-of-master/186

---

Mitmproxy Version: master
Operating System: Win10 x64

<!-- Please use the mitmproxy forums (https://discourse.mitmproxy.org/) for support/how-to questions. Thanks! :) -->



Discussion:
I am facing the same issue, some of the requests from my device are not being intercepted by mitm ( or maybe it's intercepting it but not being displayed

I am facing the same issue, some of the requests from my device are not being intercepted by mitm ( or maybe it's intercepting it but not being displayed


Resolving patch:
diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py
--- a/mitmproxy/console/master.py
+++ b/mitmproxy/console/master.py
@@ -685,24 +685,18 @@ def clear_events(self):
     # Handlers
     @controller.handler
     def error(self, f):
-        f = flow.FlowMaster.error(self, f)
-        if f:
-            self.process_flow(f)
-        return f
+        super(ConsoleMaster, self).error(f)
+        self.process_flow(f)
 
     @controller.handler
     def request(self, f):
-        f = flow.FlowMaster.request(self, f)
-        if f:
-            self.process_flow(f)
-        return f
+        super(ConsoleMaster, self).request(f)
+        self.process_flow(f)
 
     @controller.handler
     def response(self, f):
-        f = flow.FlowMaster.response(self, f)
-        if f:
-            self.process_flow(f)
-        return f
+        super(ConsoleMaster, self).response(f)
+        self.process_flow(f)
 
     @controller.handler
     def tcp_message(self, f):


Test patch:
diff --git a/test/mitmproxy/console/test_master.py b/test/mitmproxy/console/test_master.py
--- a/test/mitmproxy/console/test_master.py
+++ b/test/mitmproxy/console/test_master.py
@@ -122,3 +122,16 @@ def test_basic(self):
         for i in (1, 2, 3):
             self.dummy_cycle(m, 1, b"")
             assert len(m.state.flows) == i
+
+    def test_intercept(self):
+        """regression test for https://github.com/mitmproxy/mitmproxy/issues/1605"""
+        m = self.mkmaster(intercept="~b bar")
+        f = tutils.tflow(req=netlib.tutils.treq(content=b"foo"))
+        m.request(f)
+        assert not m.state.flows[0].intercepted
+        f = tutils.tflow(req=netlib.tutils.treq(content=b"bar"))
+        m.request(f)
+        assert m.state.flows[1].intercepted
+        f = tutils.tflow(resp=netlib.tutils.tresp(content=b"bar"))
+        m.request(f)
+        assert m.state.flows[2].intercepted