diff --git a/pappyproxy/__init__.py b/pappyproxy/__init__.py index 51e2f03..a53c568 100644 --- a/pappyproxy/__init__.py +++ b/pappyproxy/__init__.py @@ -1 +1 @@ -__version__ = '0.2.12' +__version__ = '0.2.13' diff --git a/pappyproxy/http.py b/pappyproxy/http.py index 11bb9a2..a7c46b2 100644 --- a/pappyproxy/http.py +++ b/pappyproxy/http.py @@ -1647,15 +1647,6 @@ class Request(HTTPMessage): retreq.set_websocket_messages([m.duplicate() for m in self.websocket_messages]) return retreq - def duplicate(self): - retreq = self.copy() - retreq.reqid = self.reqid - if self.unmangled: - retreq.unmangled = self.unmangled.duplicate() - if self.response: - retreq.response = self.response.duplicate() - return retreq - def duplicate(self): retreq = self.copy() retreq.reqid = self.reqid diff --git a/pappyproxy/macros.py b/pappyproxy/macros.py index 953019e..2ab6bc3 100644 --- a/pappyproxy/macros.py +++ b/pappyproxy/macros.py @@ -369,6 +369,73 @@ class MacroTemplate(object): def template_argstring(cls, template): return cls._template_data[template][2] +## Other functions + + @defer.inlineCallbacks + def async_mangle_ws(self, request, message): + if hasattr(self.source, 'async_mangle_ws'): + mangled_ws = yield self.source.async_mangle_ws(request, message) + defer.returnValue(mangled_ws) + defer.returnValue(message) + +class MacroTemplate(object): + _template_data = { + 'macro': ('macro.py.template', + 'Generic macro template', + '[reqids]', + 'macro_{fname}.py', + gen_template_args_macro), + + 'intmacro': ('intmacro.py.template', + 'Generic intercepting macro template', + '', + 'int_{fname}.py', + gen_template_generator_noargs('intmacro')), + + 'modheader': ('macro_header.py.template', + 'Modify a header in the request and the response if it exists.', + '', + 'int_{fname}.py', + gen_template_generator_noargs('modheader')), + + 'resubmit': ('macro_resubmit.py.template', + 'Resubmit all in-context requests', + '', + 'macro_{fname}.py', + gen_template_generator_noargs('resubmit')), + } + + @classmethod + def fill_template(cls, template, subs): + loader = FileSystemLoader(session.config.pappy_dir+'/templates') + env = Environment(loader=loader) + template = env.get_template(cls._template_data[template][0]) + return template.render(zip=zip, **subs) + + @classmethod + @defer.inlineCallbacks + def fill_template_args(cls, template, args=[]): + ret = cls._template_data[template][4](args) + if isinstance(ret, defer.Deferred): + ret = yield ret + defer.returnValue(ret) + + @classmethod + def template_filename(cls, template, fname): + return cls._template_data[template][3].format(fname=fname) + + @classmethod + def template_list(cls): + return [k for k, v in cls._template_data.iteritems()] + + @classmethod + def template_description(cls, template): + return cls._template_data[template][1] + + @classmethod + def template_argstring(cls, template): + return cls._template_data[template][2] + ## Other functions def load_macros(loc):