mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Remove old ReplaceHooks code
This commit is contained in:
parent
a26cc75aab
commit
821b97c19c
@ -4,7 +4,7 @@ from mitmproxy.flow import export, modules
|
||||
from mitmproxy.flow.io import FlowWriter, FilteredFlowWriter, FlowReader, read_flows_from_paths
|
||||
from mitmproxy.flow.master import FlowMaster
|
||||
from mitmproxy.flow.modules import (
|
||||
AppRegistry, ReplaceHooks, SetHeaders, StreamLargeBodies, ClientPlaybackState,
|
||||
AppRegistry, SetHeaders, StreamLargeBodies, ClientPlaybackState,
|
||||
ServerPlaybackState
|
||||
)
|
||||
from mitmproxy.flow.state import State, FlowView
|
||||
@ -16,7 +16,7 @@ __all__ = [
|
||||
"export", "modules",
|
||||
"FlowWriter", "FilteredFlowWriter", "FlowReader", "read_flows_from_paths",
|
||||
"FlowMaster",
|
||||
"AppRegistry", "ReplaceHooks", "SetHeaders", "StreamLargeBodies", "ClientPlaybackState",
|
||||
"AppRegistry", "SetHeaders", "StreamLargeBodies", "ClientPlaybackState",
|
||||
"ServerPlaybackState", "State", "FlowView",
|
||||
"options",
|
||||
]
|
||||
|
@ -1,7 +1,6 @@
|
||||
from __future__ import absolute_import, print_function, division
|
||||
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
from six.moves import urllib
|
||||
|
||||
@ -40,58 +39,6 @@ class AppRegistry:
|
||||
return self.apps.get((host, request.port), None)
|
||||
|
||||
|
||||
class ReplaceHooks:
|
||||
def __init__(self):
|
||||
self.lst = []
|
||||
|
||||
def set(self, r):
|
||||
self.clear()
|
||||
for i in r:
|
||||
self.add(*i)
|
||||
|
||||
def add(self, fpatt, rex, s):
|
||||
"""
|
||||
add a replacement hook.
|
||||
|
||||
fpatt: a string specifying a filter pattern.
|
||||
rex: a regular expression.
|
||||
s: the replacement string
|
||||
|
||||
returns true if hook was added, false if the pattern could not be
|
||||
parsed.
|
||||
"""
|
||||
cpatt = filt.parse(fpatt)
|
||||
if not cpatt:
|
||||
return False
|
||||
try:
|
||||
re.compile(rex)
|
||||
except re.error:
|
||||
return False
|
||||
self.lst.append((fpatt, rex, s, cpatt))
|
||||
return True
|
||||
|
||||
def get_specs(self):
|
||||
"""
|
||||
Retrieve the hook specifcations. Returns a list of (fpatt, rex, s)
|
||||
tuples.
|
||||
"""
|
||||
return [i[:3] for i in self.lst]
|
||||
|
||||
def count(self):
|
||||
return len(self.lst)
|
||||
|
||||
def run(self, f):
|
||||
for _, rex, s, cpatt in self.lst:
|
||||
if cpatt(f):
|
||||
if f.response:
|
||||
f.response.replace(rex, s)
|
||||
else:
|
||||
f.request.replace(rex, s)
|
||||
|
||||
def clear(self):
|
||||
self.lst = []
|
||||
|
||||
|
||||
class SetHeaders:
|
||||
def __init__(self):
|
||||
self.lst = []
|
||||
|
Loading…
Reference in New Issue
Block a user