mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
use flowfilter.match
This commit is contained in:
parent
5f8b8bf35e
commit
bb60b76af4
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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),
|
||||
|
@ -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,
|
||||
]
|
||||
)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user