diff --git a/examples/flowfilter.py b/examples/flowfilter.py index af6450106..80a153daf 100644 --- a/examples/flowfilter.py +++ b/examples/flowfilter.py @@ -1,15 +1,16 @@ # This scripts demonstrates how to use mitmproxy's filter pattern in scripts. -# Usage: mitmdump -s "filter.py FILTER" +# Usage: mitmdump -s "flowfilter.py FILTER" + import sys -from mitmproxy import filter +from mitmproxy import flowfilter class Filter: def __init__(self, spec): - self.filter = filter.parse(spec) + self.filter = flowfilter.parse(spec) def response(self, flow): - if flow.match(self.filter): + if flowfilter.match(flow, self.filter): print("Flow matches filter:") print(flow) diff --git a/mitmproxy/builtins/dumper.py b/mitmproxy/builtins/dumper.py index 0a7738a6f..addf6abcc 100644 --- a/mitmproxy/builtins/dumper.py +++ b/mitmproxy/builtins/dumper.py @@ -220,7 +220,7 @@ class Dumper(object): return False if not self.filter: return True - elif f.match(self.filter): + elif flowfilter.match(f, self.filter): return True return False diff --git a/mitmproxy/builtins/stickyauth.py b/mitmproxy/builtins/stickyauth.py index 51728c233..9e5a928f1 100644 --- a/mitmproxy/builtins/stickyauth.py +++ b/mitmproxy/builtins/stickyauth.py @@ -22,6 +22,6 @@ class StickyAuth: host = flow.request.host if "authorization" in flow.request.headers: self.hosts[host] = flow.request.headers["authorization"] - elif flow.match(self.flt): + elif flowfilter.match(flow, self.flt): if host in self.hosts: flow.request.headers["authorization"] = self.hosts[host] diff --git a/mitmproxy/builtins/stickycookie.py b/mitmproxy/builtins/stickycookie.py index 028eea9c0..23a5f062f 100644 --- a/mitmproxy/builtins/stickycookie.py +++ b/mitmproxy/builtins/stickycookie.py @@ -64,7 +64,7 @@ class StickyCookie: def request(self, flow): if self.flt: l = [] - if flow.match(self.flt): + if flowfilter.match(flow, self.flt): for domain, port, path in self.jar.keys(): match = [ domain_match(flow.request.host, domain), diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 75a27c397..2f20c087a 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -22,6 +22,7 @@ from mitmproxy import contentviews from mitmproxy import controller from mitmproxy import exceptions from mitmproxy import flow +from mitmproxy import flowfilter from mitmproxy import utils import mitmproxy.options from mitmproxy.console import flowlist @@ -134,9 +135,9 @@ class ConsoleState(flow.State): fprev, _ = self.get_from_pos(fidx - dist) fnext, _ = self.get_from_pos(fidx + dist) - if fprev and fprev.match(filt): + if fprev and flowfilter.match(fprev, filt): return fprev - elif fnext and fnext.match(filt): + elif fnext and flowfilter.match(fnext, filt): return fnext dist += 1 @@ -669,7 +670,7 @@ class ConsoleMaster(flow.FlowMaster): def process_flow(self, f): should_intercept = any( [ - self.state.intercept and f.match(self.state.intercept) and not f.request.is_replay, + self.state.intercept and flowfilter.match(f, self.state.intercept) and not f.request.is_replay, f.intercepted, ] ) diff --git a/mitmproxy/flow/io.py b/mitmproxy/flow/io.py index 276d7a5be..c12ff0e5d 100644 --- a/mitmproxy/flow/io.py +++ b/mitmproxy/flow/io.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, division import os from mitmproxy import exceptions +from mitmproxy import flowfilter from mitmproxy import models from mitmproxy.contrib import tnetstring from mitmproxy.flow import io_compat @@ -60,7 +61,7 @@ class FilteredFlowWriter: self.filt = filt def add(self, f): - if self.filt and not f.match(self.filt): + if self.filt and not flowfilter.match(f, self.filt): return d = f.get_state() tnetstring.dump(d, self.fo) diff --git a/mitmproxy/models/flow.py b/mitmproxy/models/flow.py index 6fce6e209..118aa3d18 100644 --- a/mitmproxy/models/flow.py +++ b/mitmproxy/models/flow.py @@ -8,8 +8,6 @@ from mitmproxy import stateobject from mitmproxy.models.connections import ClientConnection from mitmproxy.models.connections import ServerConnection -import six - from netlib import version from typing import Optional # noqa @@ -188,10 +186,3 @@ class Flow(stateobject.StateObject): self.reply.ack() self.reply.commit() master.handle_accept_intercept(self) - - def match(self, f): - import warnings - warnings.warn(".match() is deprecated, please use flowfilter.match(some_flow, some_filter) instead.", DeprecationWarning) - - from mitmproxy import flowfilter - return flowfilter.match(self, f) diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 6b24e55a2..a5a302a5b 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -68,14 +68,14 @@ class TestHTTPFlow(object): def test_match(self): f = tutils.tflow(resp=True) - assert not f.match("~b test") - assert f.match(None) - assert not f.match("~b test") + assert not flowfilter.match(f, "~b test") + assert flowfilter.match(f, None) + assert not flowfilter.match(f, "~b test") f = tutils.tflow(err=True) - assert f.match("~e") + assert flowfilter.match(f, "~e") - tutils.raises(ValueError, f.match, "~") + tutils.raises(ValueError, flowfilter.match, f, "~") def test_backup(self): f = tutils.tflow() @@ -195,14 +195,14 @@ class TestTCPFlow: def test_match(self): f = tutils.ttcpflow() - assert not f.match("~b nonexistent") - assert f.match(None) - assert not f.match("~b nonexistent") + assert not flowfilter.match(f, "~b nonexistent") + assert flowfilter.match(f, None) + assert not flowfilter.match(f, "~b nonexistent") f = tutils.ttcpflow(err=True) - assert f.match("~e") + assert flowfilter.match(f, "~e") - tutils.raises(ValueError, f.match, "~") + tutils.raises(ValueError, flowfilter.match, f, "~") class TestState: