From 966418725b204491d2c40358c08bf56564307412 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 19 Oct 2016 14:14:59 +1300 Subject: [PATCH 1/3] controller.Log -> log.Log --- mitmproxy/builtins/wsgiapp.py | 2 +- mitmproxy/controller.py | 41 ------------------------- mitmproxy/log.py | 40 ++++++++++++++++++++++++ mitmproxy/master.py | 5 +-- mitmproxy/proxy/root_context.py | 4 +-- mitmproxy/proxy/server.py | 4 +-- test/mitmproxy/builtins/test_termlog.py | 6 ++-- 7 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 mitmproxy/log.py diff --git a/mitmproxy/builtins/wsgiapp.py b/mitmproxy/builtins/wsgiapp.py index 9444fcec5..d83a1e2ec 100644 --- a/mitmproxy/builtins/wsgiapp.py +++ b/mitmproxy/builtins/wsgiapp.py @@ -29,7 +29,7 @@ class WSGIApp: **{"mitmproxy.master": ctx.master} ) if err: - ctx.log.warn("Error in wsgi app. %s" % err, "error") + ctx.log.error("Error in wsgi app. %s" % err) flow.reply.kill() raise exceptions.AddonHalt() diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 27fb4a0cb..c5e125ce7 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -3,47 +3,6 @@ import queue from mitmproxy import exceptions -class LogEntry: - def __init__(self, msg, level): - self.msg = msg - self.level = level - - -class Log: - """ - The central logger, exposed to scripts as mitmproxy.ctx.log. - """ - def __init__(self, master): - self.master = master - - def debug(self, txt): - """ - Log with level debug. - """ - self(txt, "debug") - - def info(self, txt): - """ - Log with level info. - """ - self(txt, "info") - - def warn(self, txt): - """ - Log with level warn. - """ - self(txt, "warn") - - def error(self, txt): - """ - Log with level error. - """ - self(txt, "error") - - def __call__(self, text, level="info"): - self.master.add_log(text, level) - - class Channel: """ The only way for the proxy server to communicate with the master diff --git a/mitmproxy/log.py b/mitmproxy/log.py new file mode 100644 index 000000000..8c28a9b14 --- /dev/null +++ b/mitmproxy/log.py @@ -0,0 +1,40 @@ + +class LogEntry: + def __init__(self, msg, level): + self.msg = msg + self.level = level + + +class Log: + """ + The central logger, exposed to scripts as mitmproxy.ctx.log. + """ + def __init__(self, master): + self.master = master + + def debug(self, txt): + """ + Log with level debug. + """ + self(txt, "debug") + + def info(self, txt): + """ + Log with level info. + """ + self(txt, "info") + + def warn(self, txt): + """ + Log with level warn. + """ + self(txt, "warn") + + def error(self, txt): + """ + Log with level error. + """ + self(txt, "error") + + def __call__(self, text, level="info"): + self.master.add_log(text, level) diff --git a/mitmproxy/master.py b/mitmproxy/master.py index b6286b89c..ce1dd2c6a 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -10,6 +10,7 @@ from mitmproxy import controller from mitmproxy import events from mitmproxy import exceptions from mitmproxy import models +from mitmproxy import log from mitmproxy.flow import io from mitmproxy.protocol import http_replay from netlib import basethread @@ -50,7 +51,7 @@ class Master: yield return mitmproxy_ctx.master = self - mitmproxy_ctx.log = controller.Log(self) + mitmproxy_ctx.log = log.Log(self) try: yield finally: @@ -66,7 +67,7 @@ class Master: level: debug, info, warn, error """ with self.handlecontext(): - self.addons("log", controller.LogEntry(e, level)) + self.addons("log", log.LogEntry(e, level)) def start(self): self.should_exit.clear() diff --git a/mitmproxy/proxy/root_context.py b/mitmproxy/proxy/root_context.py index ef6aaf36b..8064f12df 100644 --- a/mitmproxy/proxy/root_context.py +++ b/mitmproxy/proxy/root_context.py @@ -1,5 +1,5 @@ import netlib.exceptions -from mitmproxy import controller +from mitmproxy import log from mitmproxy import exceptions from mitmproxy import protocol from mitmproxy.proxy import modes @@ -113,7 +113,7 @@ class RootContext: for i in subs: full_msg.append(" -> " + i) full_msg = "\n".join(full_msg) - self.channel.tell("log", controller.LogEntry(full_msg, level)) + self.channel.tell("log", log.LogEntry(full_msg, level)) @property def layers(self): diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py index 3d66812f9..c2a6a5c3e 100644 --- a/mitmproxy/proxy/server.py +++ b/mitmproxy/proxy/server.py @@ -5,7 +5,7 @@ import traceback import netlib.exceptions from mitmproxy import exceptions from mitmproxy import models -from mitmproxy import controller +from mitmproxy import log from mitmproxy.proxy import modes from mitmproxy.proxy import root_context from netlib import tcp @@ -151,4 +151,4 @@ class ConnectionHandler: def log(self, msg, level): msg = "{}: {}".format(repr(self.client_conn.address), msg) - self.channel.tell("log", controller.LogEntry(msg, level)) + self.channel.tell("log", log.LogEntry(msg, level)) diff --git a/test/mitmproxy/builtins/test_termlog.py b/test/mitmproxy/builtins/test_termlog.py index 1564b53f1..49a8be83c 100644 --- a/test/mitmproxy/builtins/test_termlog.py +++ b/test/mitmproxy/builtins/test_termlog.py @@ -2,7 +2,7 @@ from .. import mastertest import io from mitmproxy.builtins import termlog -from mitmproxy import controller +from mitmproxy import log from mitmproxy import dump @@ -11,7 +11,7 @@ class TestTermLog(mastertest.MasterTest): t = termlog.TermLog() sio = io.StringIO() t.configure(dump.Options(tfile = sio, verbosity = 2), set([])) - t.log(controller.LogEntry("one", "info")) + t.log(log.LogEntry("one", "info")) assert "one" in sio.getvalue() - t.log(controller.LogEntry("two", "debug")) + t.log(log.LogEntry("two", "debug")) assert "two" not in sio.getvalue() From 22eebfd574c95bbaf600aa67f14e52a44345e678 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 19 Oct 2016 14:25:11 +1300 Subject: [PATCH 2/3] addons.Addons -> addonmanager, builtins -> addons --- docs/scripting/api.rst | 8 +++-- docs/scripting/overview.rst | 2 +- examples/proxapp.py | 2 +- mitmproxy/{addons.py => addonmanager.py} | 2 +- mitmproxy/addons/__init__.py | 29 ++++++++++++++++++ mitmproxy/{builtins => addons}/anticache.py | 0 mitmproxy/{builtins => addons}/anticomp.py | 0 .../{builtins => addons}/clientplayback.py | 0 mitmproxy/{builtins => addons}/dumper.py | 0 .../{builtins => addons}/filestreamer.py | 0 mitmproxy/{builtins => addons}/onboarding.py | 4 +-- .../{builtins => addons}/onboarding/app.py | 2 +- .../onboardingapp/__init__.py | 0 .../{builtins => addons}/onboardingapp/app.py | 6 ++-- .../onboardingapp/static/bootstrap.min.css | 0 .../static/fontawesome/css/font-awesome.css | 0 .../fontawesome/css/font-awesome.min.css | 0 .../static/fontawesome/fonts/FontAwesome.otf | Bin .../fontawesome/fonts/fontawesome-webfont.eot | Bin .../fontawesome/fonts/fontawesome-webfont.svg | 0 .../fontawesome/fonts/fontawesome-webfont.ttf | Bin .../fonts/fontawesome-webfont.woff | Bin .../onboardingapp/static/mitmproxy.css | 0 .../onboardingapp/templates/frame.html | 0 .../onboardingapp/templates/index.html | 0 .../onboardingapp/templates/layout.html | 0 mitmproxy/{builtins => addons}/replace.py | 0 mitmproxy/{builtins => addons}/script.py | 0 .../{builtins => addons}/serverplayback.py | 0 mitmproxy/{builtins => addons}/setheaders.py | 0 mitmproxy/{builtins => addons}/stickyauth.py | 0 .../{builtins => addons}/stickycookie.py | 0 .../{builtins => addons}/streambodies.py | 0 mitmproxy/{builtins => addons}/termlog.py | 0 mitmproxy/{builtins => addons}/wsgiapp.py | 0 mitmproxy/builtins/__init__.py | 29 ------------------ mitmproxy/console/grideditor/editors.py | 2 +- mitmproxy/console/master.py | 4 +-- mitmproxy/dump.py | 6 ++-- mitmproxy/master.py | 4 +-- mitmproxy/web/master.py | 4 +-- setup.cfg | 2 +- .../{builtins => addons}/__init__.py | 0 .../{builtins => addons}/test_anticache.py | 2 +- .../{builtins => addons}/test_anticomp.py | 2 +- .../test_clientplayback.py | 2 +- .../{builtins => addons}/test_dumper.py | 2 +- .../{builtins => addons}/test_filestreamer.py | 2 +- .../{builtins => addons}/test_onboarding.py | 2 +- .../{builtins => addons}/test_replace.py | 2 +- .../{builtins => addons}/test_script.py | 2 +- .../test_serverplayback.py | 2 +- .../{builtins => addons}/test_setheaders.py | 2 +- .../{builtins => addons}/test_stickyauth.py | 2 +- .../{builtins => addons}/test_stickycookie.py | 2 +- .../{builtins => addons}/test_streambodies.py | 2 +- .../{builtins => addons}/test_termlog.py | 2 +- .../{builtins => addons}/test_wsgiapp.py | 10 +++--- test/mitmproxy/script/test_concurrent.py | 2 +- .../{test_addons.py => test_addonmanager.py} | 4 +-- test/mitmproxy/test_examples.py | 2 +- test/mitmproxy/test_server.py | 2 +- test/mitmproxy/tools/benchtool.py | 2 +- test/netlib/http/test_request.py | 2 +- test/netlib/http/test_response.py | 2 +- 65 files changed, 81 insertions(+), 79 deletions(-) rename mitmproxy/{addons.py => addonmanager.py} (99%) create mode 100644 mitmproxy/addons/__init__.py rename mitmproxy/{builtins => addons}/anticache.py (100%) rename mitmproxy/{builtins => addons}/anticomp.py (100%) rename mitmproxy/{builtins => addons}/clientplayback.py (100%) rename mitmproxy/{builtins => addons}/dumper.py (100%) rename mitmproxy/{builtins => addons}/filestreamer.py (100%) rename mitmproxy/{builtins => addons}/onboarding.py (81%) rename mitmproxy/{builtins => addons}/onboarding/app.py (96%) rename mitmproxy/{builtins => addons}/onboardingapp/__init__.py (100%) rename mitmproxy/{builtins => addons}/onboardingapp/app.py (92%) rename mitmproxy/{builtins => addons}/onboardingapp/static/bootstrap.min.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/css/font-awesome.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/css/font-awesome.min.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/FontAwesome.otf (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff (100%) rename mitmproxy/{builtins => addons}/onboardingapp/static/mitmproxy.css (100%) rename mitmproxy/{builtins => addons}/onboardingapp/templates/frame.html (100%) rename mitmproxy/{builtins => addons}/onboardingapp/templates/index.html (100%) rename mitmproxy/{builtins => addons}/onboardingapp/templates/layout.html (100%) rename mitmproxy/{builtins => addons}/replace.py (100%) rename mitmproxy/{builtins => addons}/script.py (100%) rename mitmproxy/{builtins => addons}/serverplayback.py (100%) rename mitmproxy/{builtins => addons}/setheaders.py (100%) rename mitmproxy/{builtins => addons}/stickyauth.py (100%) rename mitmproxy/{builtins => addons}/stickycookie.py (100%) rename mitmproxy/{builtins => addons}/streambodies.py (100%) rename mitmproxy/{builtins => addons}/termlog.py (100%) rename mitmproxy/{builtins => addons}/wsgiapp.py (100%) delete mode 100644 mitmproxy/builtins/__init__.py rename test/mitmproxy/{builtins => addons}/__init__.py (100%) rename test/mitmproxy/{builtins => addons}/test_anticache.py (94%) rename test/mitmproxy/{builtins => addons}/test_anticomp.py (93%) rename test/mitmproxy/{builtins => addons}/test_clientplayback.py (95%) rename test/mitmproxy/{builtins => addons}/test_dumper.py (98%) rename test/mitmproxy/{builtins => addons}/test_filestreamer.py (95%) rename test/mitmproxy/{builtins => addons}/test_onboarding.py (90%) rename test/mitmproxy/{builtins => addons}/test_replace.py (98%) rename test/mitmproxy/{builtins => addons}/test_script.py (99%) rename test/mitmproxy/{builtins => addons}/test_serverplayback.py (99%) rename test/mitmproxy/{builtins => addons}/test_setheaders.py (97%) rename test/mitmproxy/{builtins => addons}/test_stickyauth.py (93%) rename test/mitmproxy/{builtins => addons}/test_stickycookie.py (98%) rename test/mitmproxy/{builtins => addons}/test_streambodies.py (94%) rename test/mitmproxy/{builtins => addons}/test_termlog.py (92%) rename test/mitmproxy/{builtins => addons}/test_wsgiapp.py (81%) rename test/mitmproxy/{test_addons.py => test_addonmanager.py} (85%) diff --git a/docs/scripting/api.rst b/docs/scripting/api.rst index abc9ff3e3..59ef8d95d 100644 --- a/docs/scripting/api.rst +++ b/docs/scripting/api.rst @@ -11,8 +11,8 @@ API - `mitmproxy.models.http.HTTPResponse <#mitmproxy.models.http.HTTPResponse>`_ - `mitmproxy.models.http.HTTPFlow <#mitmproxy.models.http.HTTPFlow>`_ - Logging - - `mitmproxy.controller.Log <#mitmproxy.controller.Log>`_ - - `mitmproxy.controller.LogEntry <#mitmproxy.controller.LogEntry>`_ + - `mitmproxy.log.Log <#mitmproxy.controller.Log>`_ + - `mitmproxy.log.LogEntry <#mitmproxy.controller.LogEntry>`_ Errors @@ -36,5 +36,7 @@ HTTP Logging -------- -.. autoclass:: mitmproxy.controller.Log +.. autoclass:: mitmproxy.log.Log + :inherited-members: +.. autoclass:: mitmproxy.log.LogEntry :inherited-members: diff --git a/docs/scripting/overview.rst b/docs/scripting/overview.rst index 5966eb1de..b820538e7 100644 --- a/docs/scripting/overview.rst +++ b/docs/scripting/overview.rst @@ -6,7 +6,7 @@ Overview Mitmproxy has a powerful scripting API that allows you to control almost any aspect of traffic being proxied. In fact, much of mitmproxy's own core functionality is implemented using the exact same API exposed to scripters (see -:src:`mitmproxy/builtins`). +:src:`mitmproxy/addons`). A simple example diff --git a/examples/proxapp.py b/examples/proxapp.py index b4fa8d3dd..f95c41e5c 100644 --- a/examples/proxapp.py +++ b/examples/proxapp.py @@ -4,7 +4,7 @@ instance, we're using the Flask framework (http://flask.pocoo.org/) to expose a single simplest-possible page. """ from flask import Flask -from mitmproxy.builtins import wsgiapp +from mitmproxy.addons import wsgiapp app = Flask("proxapp") diff --git a/mitmproxy/addons.py b/mitmproxy/addonmanager.py similarity index 99% rename from mitmproxy/addons.py rename to mitmproxy/addonmanager.py index 34ca8e554..db8e0cd7e 100644 --- a/mitmproxy/addons.py +++ b/mitmproxy/addonmanager.py @@ -6,7 +6,7 @@ def _get_name(itm): return getattr(itm, "name", itm.__class__.__name__.lower()) -class Addons: +class AddonManager: def __init__(self, master): self.chain = [] self.master = master diff --git a/mitmproxy/addons/__init__.py b/mitmproxy/addons/__init__.py new file mode 100644 index 000000000..c5d405253 --- /dev/null +++ b/mitmproxy/addons/__init__.py @@ -0,0 +1,29 @@ +from mitmproxy.addons import anticache +from mitmproxy.addons import anticomp +from mitmproxy.addons import clientplayback +from mitmproxy.addons import filestreamer +from mitmproxy.addons import onboarding +from mitmproxy.addons import replace +from mitmproxy.addons import script +from mitmproxy.addons import setheaders +from mitmproxy.addons import serverplayback +from mitmproxy.addons import stickyauth +from mitmproxy.addons import stickycookie +from mitmproxy.addons import streambodies + + +def default_addons(): + return [ + onboarding.Onboarding(), + anticache.AntiCache(), + anticomp.AntiComp(), + stickyauth.StickyAuth(), + stickycookie.StickyCookie(), + script.ScriptLoader(), + filestreamer.FileStreamer(), + streambodies.StreamBodies(), + replace.Replace(), + setheaders.SetHeaders(), + serverplayback.ServerPlayback(), + clientplayback.ClientPlayback(), + ] diff --git a/mitmproxy/builtins/anticache.py b/mitmproxy/addons/anticache.py similarity index 100% rename from mitmproxy/builtins/anticache.py rename to mitmproxy/addons/anticache.py diff --git a/mitmproxy/builtins/anticomp.py b/mitmproxy/addons/anticomp.py similarity index 100% rename from mitmproxy/builtins/anticomp.py rename to mitmproxy/addons/anticomp.py diff --git a/mitmproxy/builtins/clientplayback.py b/mitmproxy/addons/clientplayback.py similarity index 100% rename from mitmproxy/builtins/clientplayback.py rename to mitmproxy/addons/clientplayback.py diff --git a/mitmproxy/builtins/dumper.py b/mitmproxy/addons/dumper.py similarity index 100% rename from mitmproxy/builtins/dumper.py rename to mitmproxy/addons/dumper.py diff --git a/mitmproxy/builtins/filestreamer.py b/mitmproxy/addons/filestreamer.py similarity index 100% rename from mitmproxy/builtins/filestreamer.py rename to mitmproxy/addons/filestreamer.py diff --git a/mitmproxy/builtins/onboarding.py b/mitmproxy/addons/onboarding.py similarity index 81% rename from mitmproxy/builtins/onboarding.py rename to mitmproxy/addons/onboarding.py index 958440109..4b9524381 100644 --- a/mitmproxy/builtins/onboarding.py +++ b/mitmproxy/addons/onboarding.py @@ -1,5 +1,5 @@ -from mitmproxy.builtins import wsgiapp -from mitmproxy.builtins.onboardingapp import app +from mitmproxy.addons import wsgiapp +from mitmproxy.addons.onboardingapp import app class Onboarding(wsgiapp.WSGIApp): diff --git a/mitmproxy/builtins/onboarding/app.py b/mitmproxy/addons/onboarding/app.py similarity index 96% rename from mitmproxy/builtins/onboarding/app.py rename to mitmproxy/addons/onboarding/app.py index c7fcf87b5..20197c096 100644 --- a/mitmproxy/builtins/onboarding/app.py +++ b/mitmproxy/addons/onboarding/app.py @@ -7,7 +7,7 @@ import tornado.wsgi from mitmproxy import utils from mitmproxy.proxy import config -loader = tornado.template.Loader(utils.pkg_data.path("builtins/onboardingapp/templates")) +loader = tornado.template.Loader(utils.pkg_data.path("addons/onboardingapp/templates")) class Adapter(tornado.wsgi.WSGIAdapter): diff --git a/mitmproxy/builtins/onboardingapp/__init__.py b/mitmproxy/addons/onboardingapp/__init__.py similarity index 100% rename from mitmproxy/builtins/onboardingapp/__init__.py rename to mitmproxy/addons/onboardingapp/__init__.py diff --git a/mitmproxy/builtins/onboardingapp/app.py b/mitmproxy/addons/onboardingapp/app.py similarity index 92% rename from mitmproxy/builtins/onboardingapp/app.py rename to mitmproxy/addons/onboardingapp/app.py index 6a65d1422..9e07b75fd 100644 --- a/mitmproxy/builtins/onboardingapp/app.py +++ b/mitmproxy/addons/onboardingapp/app.py @@ -6,9 +6,9 @@ import tornado.wsgi from mitmproxy import utils from mitmproxy.proxy import config -from mitmproxy.builtins import wsgiapp +from mitmproxy.addons import wsgiapp -loader = tornado.template.Loader(utils.pkg_data.path("builtins/onboardingapp/templates")) +loader = tornado.template.Loader(utils.pkg_data.path("addons/onboardingapp/templates")) class Adapter(tornado.wsgi.WSGIAdapter): @@ -86,7 +86,7 @@ application = tornado.web.Application( r"/static/(.*)", tornado.web.StaticFileHandler, { - "path": utils.pkg_data.path("builtins/onboardingapp/static") + "path": utils.pkg_data.path("addons/onboardingapp/static") } ), ], diff --git a/mitmproxy/builtins/onboardingapp/static/bootstrap.min.css b/mitmproxy/addons/onboardingapp/static/bootstrap.min.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/bootstrap.min.css rename to mitmproxy/addons/onboardingapp/static/bootstrap.min.css diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.css b/mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.css rename to mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.css diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.min.css b/mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.min.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/css/font-awesome.min.css rename to mitmproxy/addons/onboardingapp/static/fontawesome/css/font-awesome.min.css diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/FontAwesome.otf b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/FontAwesome.otf similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/FontAwesome.otf rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/FontAwesome.otf diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.eot diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.svg diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.ttf diff --git a/mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff b/mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff rename to mitmproxy/addons/onboardingapp/static/fontawesome/fonts/fontawesome-webfont.woff diff --git a/mitmproxy/builtins/onboardingapp/static/mitmproxy.css b/mitmproxy/addons/onboardingapp/static/mitmproxy.css similarity index 100% rename from mitmproxy/builtins/onboardingapp/static/mitmproxy.css rename to mitmproxy/addons/onboardingapp/static/mitmproxy.css diff --git a/mitmproxy/builtins/onboardingapp/templates/frame.html b/mitmproxy/addons/onboardingapp/templates/frame.html similarity index 100% rename from mitmproxy/builtins/onboardingapp/templates/frame.html rename to mitmproxy/addons/onboardingapp/templates/frame.html diff --git a/mitmproxy/builtins/onboardingapp/templates/index.html b/mitmproxy/addons/onboardingapp/templates/index.html similarity index 100% rename from mitmproxy/builtins/onboardingapp/templates/index.html rename to mitmproxy/addons/onboardingapp/templates/index.html diff --git a/mitmproxy/builtins/onboardingapp/templates/layout.html b/mitmproxy/addons/onboardingapp/templates/layout.html similarity index 100% rename from mitmproxy/builtins/onboardingapp/templates/layout.html rename to mitmproxy/addons/onboardingapp/templates/layout.html diff --git a/mitmproxy/builtins/replace.py b/mitmproxy/addons/replace.py similarity index 100% rename from mitmproxy/builtins/replace.py rename to mitmproxy/addons/replace.py diff --git a/mitmproxy/builtins/script.py b/mitmproxy/addons/script.py similarity index 100% rename from mitmproxy/builtins/script.py rename to mitmproxy/addons/script.py diff --git a/mitmproxy/builtins/serverplayback.py b/mitmproxy/addons/serverplayback.py similarity index 100% rename from mitmproxy/builtins/serverplayback.py rename to mitmproxy/addons/serverplayback.py diff --git a/mitmproxy/builtins/setheaders.py b/mitmproxy/addons/setheaders.py similarity index 100% rename from mitmproxy/builtins/setheaders.py rename to mitmproxy/addons/setheaders.py diff --git a/mitmproxy/builtins/stickyauth.py b/mitmproxy/addons/stickyauth.py similarity index 100% rename from mitmproxy/builtins/stickyauth.py rename to mitmproxy/addons/stickyauth.py diff --git a/mitmproxy/builtins/stickycookie.py b/mitmproxy/addons/stickycookie.py similarity index 100% rename from mitmproxy/builtins/stickycookie.py rename to mitmproxy/addons/stickycookie.py diff --git a/mitmproxy/builtins/streambodies.py b/mitmproxy/addons/streambodies.py similarity index 100% rename from mitmproxy/builtins/streambodies.py rename to mitmproxy/addons/streambodies.py diff --git a/mitmproxy/builtins/termlog.py b/mitmproxy/addons/termlog.py similarity index 100% rename from mitmproxy/builtins/termlog.py rename to mitmproxy/addons/termlog.py diff --git a/mitmproxy/builtins/wsgiapp.py b/mitmproxy/addons/wsgiapp.py similarity index 100% rename from mitmproxy/builtins/wsgiapp.py rename to mitmproxy/addons/wsgiapp.py diff --git a/mitmproxy/builtins/__init__.py b/mitmproxy/builtins/__init__.py deleted file mode 100644 index 54b52a9a6..000000000 --- a/mitmproxy/builtins/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -from mitmproxy.builtins import anticache -from mitmproxy.builtins import anticomp -from mitmproxy.builtins import clientplayback -from mitmproxy.builtins import filestreamer -from mitmproxy.builtins import onboarding -from mitmproxy.builtins import replace -from mitmproxy.builtins import script -from mitmproxy.builtins import setheaders -from mitmproxy.builtins import serverplayback -from mitmproxy.builtins import stickyauth -from mitmproxy.builtins import stickycookie -from mitmproxy.builtins import streambodies - - -def default_addons(): - return [ - onboarding.Onboarding(), - anticache.AntiCache(), - anticomp.AntiComp(), - stickyauth.StickyAuth(), - stickycookie.StickyCookie(), - script.ScriptLoader(), - filestreamer.FileStreamer(), - streambodies.StreamBodies(), - replace.Replace(), - setheaders.SetHeaders(), - serverplayback.ServerPlayback(), - clientplayback.ClientPlayback(), - ] diff --git a/mitmproxy/console/grideditor/editors.py b/mitmproxy/console/grideditor/editors.py index 7a1ef0978..512c2416f 100644 --- a/mitmproxy/console/grideditor/editors.py +++ b/mitmproxy/console/grideditor/editors.py @@ -2,7 +2,7 @@ import re import urwid from mitmproxy import exceptions from mitmproxy import flowfilter -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy.console import common from mitmproxy.console.grideditor import base from mitmproxy.console.grideditor import col_bytes diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index b19c62a2b..4e49a51a9 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -14,7 +14,7 @@ import weakref import urwid from typing import Optional -from mitmproxy import builtins +from mitmproxy import addons from mitmproxy import contentviews from mitmproxy import controller from mitmproxy import exceptions @@ -251,7 +251,7 @@ class ConsoleMaster(master.Master): signals.replace_view_state.connect(self.sig_replace_view_state) signals.push_view_state.connect(self.sig_push_view_state) signals.sig_add_log.connect(self.sig_add_log) - self.addons.add(*builtins.default_addons()) + self.addons.add(*addons.default_addons()) self.addons.add(self.state) def __setattr__(self, name, value): diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index 4731686c9..e8b3126f3 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -4,10 +4,10 @@ from typing import Optional from mitmproxy import controller from mitmproxy import exceptions from mitmproxy import flow -from mitmproxy import builtins +from mitmproxy import addons from mitmproxy import options from mitmproxy import master -from mitmproxy.builtins import dumper, termlog +from mitmproxy.addons import dumper, termlog from netlib import tcp @@ -37,7 +37,7 @@ class DumpMaster(master.Master): master.Master.__init__(self, options, server) self.has_errored = False self.addons.add(termlog.TermLog()) - self.addons.add(*builtins.default_addons()) + self.addons.add(*addons.default_addons()) self.addons.add(dumper.Dumper()) # This line is just for type hinting self.options = self.options # type: Options diff --git a/mitmproxy/master.py b/mitmproxy/master.py index ce1dd2c6a..aa9892e59 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -4,7 +4,7 @@ import contextlib import queue import sys -from mitmproxy import addons +from mitmproxy import addonmanager from mitmproxy import options from mitmproxy import controller from mitmproxy import events @@ -37,7 +37,7 @@ class Master: """ def __init__(self, opts, server): self.options = opts or options.Options() - self.addons = addons.Addons(self) + self.addons = addonmanager.AddonManager(self) self.event_queue = queue.Queue() self.should_exit = threading.Event() self.server = server diff --git a/mitmproxy/web/master.py b/mitmproxy/web/master.py index 1f0dc709e..c7976fcb3 100644 --- a/mitmproxy/web/master.py +++ b/mitmproxy/web/master.py @@ -6,7 +6,7 @@ import tornado.ioloop from typing import Optional -from mitmproxy import builtins +from mitmproxy import addons from mitmproxy import controller from mitmproxy import exceptions from mitmproxy import flow @@ -136,7 +136,7 @@ class WebMaster(master.Master): def __init__(self, options, server): super().__init__(options, server) self.state = WebState() - self.addons.add(*builtins.default_addons()) + self.addons.add(*addons.default_addons()) self.addons.add(self.state) self.app = app.Application( self, self.options.wdebug, self.options.wauthenticator diff --git a/setup.cfg b/setup.cfg index 47fe119ae..87ef81ede 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ max-line-length = 140 max-complexity = 25 ignore = E251,C901 exclude = mitmproxy/contrib/*,test/mitmproxy/data/* -builtins = file,open,basestring,xrange,unicode,long,cmp +addons = file,open,basestring,xrange,unicode,long,cmp [tool:pytest] testpaths = test diff --git a/test/mitmproxy/builtins/__init__.py b/test/mitmproxy/addons/__init__.py similarity index 100% rename from test/mitmproxy/builtins/__init__.py rename to test/mitmproxy/addons/__init__.py diff --git a/test/mitmproxy/builtins/test_anticache.py b/test/mitmproxy/addons/test_anticache.py similarity index 94% rename from test/mitmproxy/builtins/test_anticache.py rename to test/mitmproxy/addons/test_anticache.py index 790ae97d2..f7418f389 100644 --- a/test/mitmproxy/builtins/test_anticache.py +++ b/test/mitmproxy/addons/test_anticache.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import anticache +from mitmproxy.addons import anticache from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_anticomp.py b/test/mitmproxy/addons/test_anticomp.py similarity index 93% rename from test/mitmproxy/builtins/test_anticomp.py rename to test/mitmproxy/addons/test_anticomp.py index d5a0d6eb7..5f95013f9 100644 --- a/test/mitmproxy/builtins/test_anticomp.py +++ b/test/mitmproxy/addons/test_anticomp.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import anticomp +from mitmproxy.addons import anticomp from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_clientplayback.py b/test/mitmproxy/addons/test_clientplayback.py similarity index 95% rename from test/mitmproxy/builtins/test_clientplayback.py rename to test/mitmproxy/addons/test_clientplayback.py index e2c5be7e7..c5407d187 100644 --- a/test/mitmproxy/builtins/test_clientplayback.py +++ b/test/mitmproxy/addons/test_clientplayback.py @@ -1,6 +1,6 @@ import mock -from mitmproxy.builtins import clientplayback +from mitmproxy.addons import clientplayback from mitmproxy import options from .. import tutils, mastertest diff --git a/test/mitmproxy/builtins/test_dumper.py b/test/mitmproxy/addons/test_dumper.py similarity index 98% rename from test/mitmproxy/builtins/test_dumper.py rename to test/mitmproxy/addons/test_dumper.py index d5291bc49..ce2d2de9a 100644 --- a/test/mitmproxy/builtins/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -2,7 +2,7 @@ import io from .. import tutils, mastertest -from mitmproxy.builtins import dumper +from mitmproxy.addons import dumper from mitmproxy import exceptions from mitmproxy import dump from mitmproxy import models diff --git a/test/mitmproxy/builtins/test_filestreamer.py b/test/mitmproxy/addons/test_filestreamer.py similarity index 95% rename from test/mitmproxy/builtins/test_filestreamer.py rename to test/mitmproxy/addons/test_filestreamer.py index 35fe1ca2a..a85fcd0c2 100644 --- a/test/mitmproxy/builtins/test_filestreamer.py +++ b/test/mitmproxy/addons/test_filestreamer.py @@ -2,7 +2,7 @@ from .. import tutils, mastertest import os.path -from mitmproxy.builtins import filestreamer +from mitmproxy.addons import filestreamer from mitmproxy import master from mitmproxy.flow import io from mitmproxy import options diff --git a/test/mitmproxy/builtins/test_onboarding.py b/test/mitmproxy/addons/test_onboarding.py similarity index 90% rename from test/mitmproxy/builtins/test_onboarding.py rename to test/mitmproxy/addons/test_onboarding.py index 3226aec36..63125c23a 100644 --- a/test/mitmproxy/builtins/test_onboarding.py +++ b/test/mitmproxy/addons/test_onboarding.py @@ -1,4 +1,4 @@ -from mitmproxy.builtins import onboarding +from mitmproxy.addons import onboarding from .. import tservers diff --git a/test/mitmproxy/builtins/test_replace.py b/test/mitmproxy/addons/test_replace.py similarity index 98% rename from test/mitmproxy/builtins/test_replace.py rename to test/mitmproxy/addons/test_replace.py index 35f3d4301..94c2f832b 100644 --- a/test/mitmproxy/builtins/test_replace.py +++ b/test/mitmproxy/addons/test_replace.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest, tservers -from mitmproxy.builtins import replace +from mitmproxy.addons import replace from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/addons/test_script.py similarity index 99% rename from test/mitmproxy/builtins/test_script.py rename to test/mitmproxy/addons/test_script.py index ab4343b5e..83e60fbda 100644 --- a/test/mitmproxy/builtins/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -7,7 +7,7 @@ import re from mitmproxy import exceptions from mitmproxy import options from mitmproxy import proxy -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy import master from .. import tutils, mastertest diff --git a/test/mitmproxy/builtins/test_serverplayback.py b/test/mitmproxy/addons/test_serverplayback.py similarity index 99% rename from test/mitmproxy/builtins/test_serverplayback.py rename to test/mitmproxy/addons/test_serverplayback.py index c51814f51..649b3c227 100644 --- a/test/mitmproxy/builtins/test_serverplayback.py +++ b/test/mitmproxy/addons/test_serverplayback.py @@ -1,7 +1,7 @@ from .. import tutils, mastertest import netlib.tutils -from mitmproxy.builtins import serverplayback +from mitmproxy.addons import serverplayback from mitmproxy import options from mitmproxy import proxy from mitmproxy import exceptions diff --git a/test/mitmproxy/builtins/test_setheaders.py b/test/mitmproxy/addons/test_setheaders.py similarity index 97% rename from test/mitmproxy/builtins/test_setheaders.py rename to test/mitmproxy/addons/test_setheaders.py index bac8b02ee..0fbbd4cb0 100644 --- a/test/mitmproxy/builtins/test_setheaders.py +++ b/test/mitmproxy/addons/test_setheaders.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest -from mitmproxy.builtins import setheaders +from mitmproxy.addons import setheaders from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_stickyauth.py b/test/mitmproxy/addons/test_stickyauth.py similarity index 93% rename from test/mitmproxy/builtins/test_stickyauth.py rename to test/mitmproxy/addons/test_stickyauth.py index 225235488..459dc5f71 100644 --- a/test/mitmproxy/builtins/test_stickyauth.py +++ b/test/mitmproxy/addons/test_stickyauth.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import stickyauth +from mitmproxy.addons import stickyauth from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_stickycookie.py b/test/mitmproxy/addons/test_stickycookie.py similarity index 98% rename from test/mitmproxy/builtins/test_stickycookie.py rename to test/mitmproxy/addons/test_stickycookie.py index c70b03d8c..29c9e198b 100644 --- a/test/mitmproxy/builtins/test_stickycookie.py +++ b/test/mitmproxy/addons/test_stickycookie.py @@ -1,5 +1,5 @@ from .. import tutils, mastertest -from mitmproxy.builtins import stickycookie +from mitmproxy.addons import stickycookie from mitmproxy import master from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/builtins/test_streambodies.py b/test/mitmproxy/addons/test_streambodies.py similarity index 94% rename from test/mitmproxy/builtins/test_streambodies.py rename to test/mitmproxy/addons/test_streambodies.py index 4a8c24740..cf416c864 100644 --- a/test/mitmproxy/builtins/test_streambodies.py +++ b/test/mitmproxy/addons/test_streambodies.py @@ -3,7 +3,7 @@ from mitmproxy import master from mitmproxy import options from mitmproxy import proxy -from mitmproxy.builtins import streambodies +from mitmproxy.addons import streambodies class TestStreamBodies(mastertest.MasterTest): diff --git a/test/mitmproxy/builtins/test_termlog.py b/test/mitmproxy/addons/test_termlog.py similarity index 92% rename from test/mitmproxy/builtins/test_termlog.py rename to test/mitmproxy/addons/test_termlog.py index 49a8be83c..a9f18a51a 100644 --- a/test/mitmproxy/builtins/test_termlog.py +++ b/test/mitmproxy/addons/test_termlog.py @@ -1,7 +1,7 @@ from .. import mastertest import io -from mitmproxy.builtins import termlog +from mitmproxy.addons import termlog from mitmproxy import log from mitmproxy import dump diff --git a/test/mitmproxy/builtins/test_wsgiapp.py b/test/mitmproxy/addons/test_wsgiapp.py similarity index 81% rename from test/mitmproxy/builtins/test_wsgiapp.py rename to test/mitmproxy/addons/test_wsgiapp.py index a39ec5c30..760ee460b 100644 --- a/test/mitmproxy/builtins/test_wsgiapp.py +++ b/test/mitmproxy/addons/test_wsgiapp.py @@ -1,17 +1,17 @@ import flask from .. import tservers -from mitmproxy.builtins import wsgiapp +from mitmproxy.addons import wsgiapp -testapp = flask.Flask(__name__) +tapp = flask.Flask(__name__) -@testapp.route("/") +@tapp.route("/") def hello(): return "testapp" -@testapp.route("/error") +@tapp.route("/error") def error(): raise ValueError("An exception...") @@ -23,7 +23,7 @@ def errapp(environ, start_response): class TestApp(tservers.HTTPProxyTest): def addons(self): return [ - wsgiapp.WSGIApp(testapp, "testapp", 80), + wsgiapp.WSGIApp(tapp, "testapp", 80), wsgiapp.WSGIApp(errapp, "errapp", 80) ] diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py index bebd8dea6..51c36abf8 100644 --- a/test/mitmproxy/script/test_concurrent.py +++ b/test/mitmproxy/script/test_concurrent.py @@ -1,6 +1,6 @@ from test.mitmproxy import tutils, mastertest from mitmproxy import controller -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy import options from mitmproxy import proxy from mitmproxy import master diff --git a/test/mitmproxy/test_addons.py b/test/mitmproxy/test_addonmanager.py similarity index 85% rename from test/mitmproxy/test_addons.py rename to test/mitmproxy/test_addonmanager.py index dcf14398b..7a50148e0 100644 --- a/test/mitmproxy/test_addons.py +++ b/test/mitmproxy/test_addonmanager.py @@ -1,4 +1,4 @@ -from mitmproxy import addons +from mitmproxy import addonmanager from mitmproxy import options from mitmproxy import master from mitmproxy import proxy @@ -15,7 +15,7 @@ class TAddon: def test_simple(): o = options.Options() m = master.Master(o, proxy.DummyServer(o)) - a = addons.Addons(m) + a = addonmanager.AddonManager(m) a.add(TAddon("one")) assert a.get("one") assert not a.get("two") diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index ee5080e8b..7551c1c84 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -5,7 +5,7 @@ import shlex from mitmproxy import options from mitmproxy import contentviews from mitmproxy import proxy -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy import master import netlib.utils diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py index 6679625bc..7616b5a78 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -5,7 +5,7 @@ import time import netlib.tutils from mitmproxy import controller from mitmproxy import options -from mitmproxy.builtins import script +from mitmproxy.addons import script from mitmproxy.models import HTTPResponse, HTTPFlow from mitmproxy.proxy.config import HostMatcher, parse_server_spec from netlib import tcp, http, socks diff --git a/test/mitmproxy/tools/benchtool.py b/test/mitmproxy/tools/benchtool.py index bc68645cd..9e2ab8eea 100644 --- a/test/mitmproxy/tools/benchtool.py +++ b/test/mitmproxy/tools/benchtool.py @@ -38,7 +38,7 @@ def main(profiler, clock_type, concurrency): if profiler == "yappi": yappi.set_clock_type(clock_type) - yappi.start(builtins=True) + yappi.start(addons=True) print("Start mitmdump...") mitmdump(["-k", "-q", "-S", "1024example"]) diff --git a/test/netlib/http/test_request.py b/test/netlib/http/test_request.py index 87eb9c351..336dc86d8 100644 --- a/test/netlib/http/test_request.py +++ b/test/netlib/http/test_request.py @@ -15,7 +15,7 @@ class TestRequestData: class TestRequestCore: """ - Tests for builtins and the attributes that are directly proxied from the data structure + Tests for addons and the attributes that are directly proxied from the data structure """ def test_repr(self): request = treq() diff --git a/test/netlib/http/test_response.py b/test/netlib/http/test_response.py index 0953f2785..725f2b332 100644 --- a/test/netlib/http/test_response.py +++ b/test/netlib/http/test_response.py @@ -19,7 +19,7 @@ class TestResponseData: class TestResponseCore: """ - Tests for builtins and the attributes that are directly proxied from the data structure + Tests for addons and the attributes that are directly proxied from the data structure """ def test_repr(self): response = tresp() From 7c32d4ea2a435484e83aa459831f74ca483d8e3c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 19 Oct 2016 14:48:42 +1300 Subject: [PATCH 3/3] flow.state -> addons.state --- examples/flowbasic | 2 +- mitmproxy/addons/onboarding/app.py | 93 ------------------- mitmproxy/{flow => addons}/state.py | 0 mitmproxy/console/master.py | 5 +- mitmproxy/flow/__init__.py | 2 - mitmproxy/web/master.py | 6 +- .../test_state.py} | 7 +- test/mitmproxy/test_flow.py | 27 +++--- test/mitmproxy/tservers.py | 2 +- 9 files changed, 26 insertions(+), 118 deletions(-) delete mode 100644 mitmproxy/addons/onboarding/app.py rename mitmproxy/{flow => addons}/state.py (100%) rename test/mitmproxy/{test_flow_state.py => addons/test_state.py} (83%) diff --git a/examples/flowbasic b/examples/flowbasic index 0eb163a40..bac98916b 100755 --- a/examples/flowbasic +++ b/examples/flowbasic @@ -37,7 +37,7 @@ class MyMaster(master.Master): opts = options.Options(cadir="~/.mitmproxy/") config = ProxyConfig(opts) -state = flow.State() +state = state.State() server = ProxyServer(config) m = MyMaster(opts, server, state) m.run() diff --git a/mitmproxy/addons/onboarding/app.py b/mitmproxy/addons/onboarding/app.py deleted file mode 100644 index 20197c096..000000000 --- a/mitmproxy/addons/onboarding/app.py +++ /dev/null @@ -1,93 +0,0 @@ -import os - -import tornado.template -import tornado.web -import tornado.wsgi - -from mitmproxy import utils -from mitmproxy.proxy import config - -loader = tornado.template.Loader(utils.pkg_data.path("addons/onboardingapp/templates")) - - -class Adapter(tornado.wsgi.WSGIAdapter): - # Tornado doesn't make the WSGI environment available to pages, so this - # hideous monkey patch is the easiest way to get to the mitmproxy.master - # variable. - - def __init__(self, application): - self._application = application - - def application(self, request): - request.master = self.environ["mitmproxy.master"] - return self._application(request) - - def __call__(self, environ, start_response): - self.environ = environ - return tornado.wsgi.WSGIAdapter.__call__( - self, - environ, - start_response - ) - - -class Index(tornado.web.RequestHandler): - - def get(self): - t = loader.load("index.html") - self.write(t.generate()) - - -class PEM(tornado.web.RequestHandler): - - @property - def filename(self): - return config.CONF_BASENAME + "-ca-cert.pem" - - def get(self): - p = os.path.join(self.request.master.options.cadir, self.filename) - p = os.path.expanduser(p) - self.set_header("Content-Type", "application/x-x509-ca-cert") - self.set_header( - "Content-Disposition", - "inline; filename={}".format( - self.filename)) - - with open(p, "rb") as f: - self.write(f.read()) - - -class P12(tornado.web.RequestHandler): - - @property - def filename(self): - return config.CONF_BASENAME + "-ca-cert.p12" - - def get(self): - p = os.path.join(self.request.master.options.cadir, self.filename) - p = os.path.expanduser(p) - self.set_header("Content-Type", "application/x-pkcs12") - self.set_header( - "Content-Disposition", - "inline; filename={}".format( - self.filename)) - - with open(p, "rb") as f: - self.write(f.read()) - - -application = tornado.web.Application( - [ - (r"/", Index), - (r"/cert/pem", PEM), - (r"/cert/p12", P12), - ( - r"/static/(.*)", - tornado.web.StaticFileHandler, - { - "path": utils.pkg_data.path("onboarding/static") - } - ), - ], - # debug=True -) diff --git a/mitmproxy/flow/state.py b/mitmproxy/addons/state.py similarity index 100% rename from mitmproxy/flow/state.py rename to mitmproxy/addons/state.py diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 4e49a51a9..46dd82542 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -22,6 +22,7 @@ from mitmproxy import master from mitmproxy import flow from mitmproxy import flowfilter from mitmproxy import utils +from mitmproxy.addons import state import mitmproxy.options from mitmproxy.console import flowlist from mitmproxy.console import flowview @@ -39,10 +40,10 @@ from netlib import tcp, strutils EVENTLOG_SIZE = 500 -class ConsoleState(flow.State): +class ConsoleState(state.State): def __init__(self): - flow.State.__init__(self) + state.State.__init__(self) self.focus = None self.follow_focus = None self.default_body_view = contentviews.get("Auto") diff --git a/mitmproxy/flow/__init__.py b/mitmproxy/flow/__init__.py index 2688966a5..69e3ed085 100644 --- a/mitmproxy/flow/__init__.py +++ b/mitmproxy/flow/__init__.py @@ -1,9 +1,7 @@ from mitmproxy.flow import export from mitmproxy.flow.io import FlowWriter, FilteredFlowWriter, FlowReader, read_flows_from_paths -from mitmproxy.flow.state import State, FlowView __all__ = [ "export", "FlowWriter", "FilteredFlowWriter", "FlowReader", "read_flows_from_paths", - "State", "FlowView", ] diff --git a/mitmproxy/web/master.py b/mitmproxy/web/master.py index c7976fcb3..f07d28c8c 100644 --- a/mitmproxy/web/master.py +++ b/mitmproxy/web/master.py @@ -9,7 +9,7 @@ from typing import Optional from mitmproxy import addons from mitmproxy import controller from mitmproxy import exceptions -from mitmproxy import flow +from mitmproxy.addons import state from mitmproxy import options from mitmproxy import master from mitmproxy.web import app @@ -20,7 +20,7 @@ class Stop(Exception): pass -class WebFlowView(flow.FlowView): +class WebFlowView(state.FlowView): def __init__(self, store): super().__init__(store, None) @@ -57,7 +57,7 @@ class WebFlowView(flow.FlowView): ) -class WebState(flow.State): +class WebState(state.State): def __init__(self): super().__init__() diff --git a/test/mitmproxy/test_flow_state.py b/test/mitmproxy/addons/test_state.py similarity index 83% rename from test/mitmproxy/test_flow_state.py rename to test/mitmproxy/addons/test_state.py index 05f4cbb43..71c46dcbc 100644 --- a/test/mitmproxy/test_flow_state.py +++ b/test/mitmproxy/addons/test_state.py @@ -1,12 +1,13 @@ -from mitmproxy import flow from mitmproxy import proxy from mitmproxy import master -from . import tutils +from mitmproxy.addons import state + +from .. import tutils class TestState: def test_duplicate_flow(self): - s = flow.State() + s = state.State() fm = master.Master(None, proxy.DummyServer()) fm.addons.add(s) f = tutils.tflow(resp=True) diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 2b387f5c7..86cd7d160 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -4,6 +4,7 @@ import io import netlib.utils from netlib.http import Headers from mitmproxy import flowfilter, flow, options +from mitmproxy.addons import state from mitmproxy.contrib import tnetstring from mitmproxy.exceptions import FlowReadException, Kill from mitmproxy.models import Error @@ -110,7 +111,7 @@ class TestHTTPFlow: def test_killall(self): srv = DummyServer(None) - s = flow.State() + s = state.State() fm = master.Master(None, srv) fm.addons.add(s) @@ -190,7 +191,7 @@ class TestTCPFlow: class TestState: def test_backup(self): - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) f.backup() @@ -202,7 +203,7 @@ class TestState: connect -> request -> response """ - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) assert f @@ -226,13 +227,13 @@ class TestState: assert c.active_flow_count() == 0 def test_err(self): - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) f.error = Error("message") assert c.update_flow(f) - c = flow.State() + c = state.State() f = tutils.tflow() c.add_flow(f) c.set_view_filter("~e") @@ -242,7 +243,7 @@ class TestState: assert c.view def test_set_view_filter(self): - c = flow.State() + c = state.State() f = tutils.tflow() assert len(c.view) == 0 @@ -270,7 +271,7 @@ class TestState: assert "Invalid" in c.set_view_filter("~") def test_set_intercept(self): - c = flow.State() + c = state.State() assert not c.set_intercept("~q") assert c.intercept_txt == "~q" assert "Invalid" in c.set_intercept("~") @@ -293,7 +294,7 @@ class TestState: state.add_flow(f) def test_clear(self): - c = flow.State() + c = state.State() f = self._add_request(c) f.intercepted = True @@ -301,7 +302,7 @@ class TestState: assert c.flow_count() == 0 def test_dump_flows(self): - c = flow.State() + c = state.State() self._add_request(c) self._add_response(c) self._add_request(c) @@ -317,7 +318,7 @@ class TestState: assert isinstance(c.flows[0], Flow) def test_accept_all(self): - c = flow.State() + c = state.State() self._add_request(c) self._add_response(c) self._add_request(c) @@ -363,7 +364,7 @@ class TestSerialize: def test_load_flows(self): r = self._treader() - s = flow.State() + s = state.State() fm = master.Master(None, DummyServer()) fm.addons.add(s) fm.load_flows(r) @@ -371,7 +372,7 @@ class TestSerialize: def test_load_flows_reverse(self): r = self._treader() - s = flow.State() + s = state.State() opts = options.Options( mode="reverse", upstream_server="https://use-this-domain" @@ -440,7 +441,7 @@ class TestFlowMaster: assert fm.create_request("GET", "http", "example.com", 80, "/") def test_all(self): - s = flow.State() + s = state.State() fm = master.Master(None, DummyServer()) fm.addons.add(s) f = tutils.tflow(req=None) diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index 254af2f09..1243bca05 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -7,7 +7,7 @@ import sys from mitmproxy.proxy.config import ProxyConfig from mitmproxy.proxy.server import ProxyServer from mitmproxy import master -from mitmproxy.flow import state +from mitmproxy.addons import state import pathod.test import pathod.pathoc from mitmproxy import controller, options