mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
Merge pull request #1632 from cortesi/refactor
Start rationalising our module structure bit by bit
This commit is contained in:
commit
49346c5248
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
29
mitmproxy/addons/__init__.py
Normal file
29
mitmproxy/addons/__init__.py
Normal file
@ -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(),
|
||||
]
|
@ -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):
|
@ -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")
|
||||
}
|
||||
),
|
||||
],
|
Before Width: | Height: | Size: 197 KiB After Width: | Height: | Size: 197 KiB |
@ -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()
|
||||
|
@ -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(),
|
||||
]
|
@ -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("builtins/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
|
||||
)
|
@ -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
|
||||
|
@ -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
|
||||
@ -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")
|
||||
@ -251,7 +252,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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
]
|
||||
|
40
mitmproxy/log.py
Normal file
40
mitmproxy/log.py
Normal file
@ -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)
|
@ -4,12 +4,13 @@ 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
|
||||
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
|
||||
@ -36,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
|
||||
@ -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()
|
||||
|
@ -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):
|
||||
|
@ -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))
|
||||
|
@ -6,10 +6,10 @@ 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
|
||||
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__()
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -1,6 +1,6 @@
|
||||
import mock
|
||||
|
||||
from mitmproxy.builtins import clientplayback
|
||||
from mitmproxy.addons import clientplayback
|
||||
from mitmproxy import options
|
||||
|
||||
from .. import tutils, mastertest
|
@ -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
|
@ -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
|
@ -1,4 +1,4 @@
|
||||
from mitmproxy.builtins import onboarding
|
||||
from mitmproxy.addons import onboarding
|
||||
from .. import tservers
|
||||
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
||||
|
@ -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)
|
@ -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
|
@ -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
|
@ -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):
|
@ -1,8 +1,8 @@
|
||||
from .. import mastertest
|
||||
import io
|
||||
|
||||
from mitmproxy.builtins import termlog
|
||||
from mitmproxy import controller
|
||||
from mitmproxy.addons import termlog
|
||||
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()
|
@ -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)
|
||||
]
|
||||
|
@ -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
|
||||
|
@ -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")
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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"])
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user