Removed replace-from-file option.Made requested changes

This commit is contained in:
Ujjwal Verma 2017-03-09 23:20:35 +05:30
parent 98b5893855
commit 07a8c4987a
5 changed files with 15 additions and 22 deletions

View File

@ -30,7 +30,6 @@ def default_addons():
onboarding.Onboarding(),
proxyauth.ProxyAuth(),
replace.Replace(),
replace.ReplaceFile(),
script.ScriptLoader(),
serverplayback.ServerPlayback(),
setheaders.SetHeaders(),

View File

@ -1,3 +1,4 @@
import os
import re
from mitmproxy import exceptions
@ -58,7 +59,6 @@ class _ReplaceBase:
lst = []
for rep in getattr(options, self.optionName):
fpatt, rex, s = parse_hook(rep)
flt = flowfilter.parse(fpatt)
if not flt:
raise exceptions.OptionsError(
@ -94,16 +94,11 @@ class Replace(_ReplaceBase):
optionName = "replacements"
def replace(self, obj, rex, s):
if s.startswith("@"):
s = s.replace("@", "")
try:
s = open(os.path.expanduser(s), "rb").read()
except IOError as e:
ctx.log.warn("Could not read replacement file: %s" % s)
return
obj.replace(rex, s, flags=re.DOTALL)
class ReplaceFile(_ReplaceBase):
optionName = "replacement_files"
def replace(self, obj, rex, s):
try:
v = open(s, "rb").read()
except IOError as e:
ctx.log.warn("Could not read replacement file: %s" % s)
return
obj.replace(rex, v, flags=re.DOTALL)

View File

@ -120,13 +120,7 @@ class Options(optmanager.OptManager):
the separator can be any character.
"""
)
self.add_option(
"replacement_files", Sequence[str], [],
"""
Replacement pattern, where the replacement clause is a path to a
file.
"""
)
self.add_option(
"server_replay_use_headers", Sequence[str], [],
"Request headers to be considered during replay."

View File

@ -93,7 +93,6 @@ def common_options(parser, opts):
# Replacements
group = parser.add_argument_group("Replacements")
opts.make_parser(group, "replacements", metavar="PATTERN", short="R")
opts.make_parser(group, "replacement_files", metavar="PATTERN")
# Set headers
group = parser.add_argument_group("Set Headers")

View File

@ -1,5 +1,8 @@
import os
import re
import urwid
from mitmproxy import exceptions
from mitmproxy import flowfilter
from mitmproxy.addons import script
@ -87,6 +90,9 @@ class ReplaceEditor(base.GridEditor):
re.compile(val)
except re.error:
return "Invalid regular expression."
elif col == 2:
if val.startswith("@") and not os.path.isfile(os.path.expanduser(val.replace("@", ""))):
return "Invalid file path"
return False