aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-10-19 11:48:51 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-10-19 11:48:51 +1300
commit87629586ae5add2d605b55e65cebc1e144c612d9 (patch)
treefe5946f7e82ff9328a8cff0b1ad6a4c660a1b742
parent85015fe561547a51bc229318287920d31caec985 (diff)
downloadmitmproxy-87629586ae5add2d605b55e65cebc1e144c612d9.tar.gz
mitmproxy-87629586ae5add2d605b55e65cebc1e144c612d9.tar.bz2
mitmproxy-87629586ae5add2d605b55e65cebc1e144c612d9.zip
web app cleanups: tests and examples
-rw-r--r--examples/proxapp.py10
-rw-r--r--mitmproxy/builtins/wsgiapp.py4
-rw-r--r--test/mitmproxy/builtins/test_wsgiapp.py22
3 files changed, 10 insertions, 26 deletions
diff --git a/examples/proxapp.py b/examples/proxapp.py
index 2935b587..b4fa8d3d 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
-import mitmproxy
+from mitmproxy.builtins import wsgiapp
app = Flask("proxapp")
@@ -14,12 +14,12 @@ def hello_world():
return 'Hello World!'
-# Register the app using the magic domain "proxapp" on port 80. Requests to
-# this domain and port combination will now be routed to the WSGI app instance.
def start():
- mitmproxy.ctx.master.apps.add(app, "proxapp", 80)
+ # Host app at the magic domain "proxapp" on port 80. Requests to this
+ # domain and port combination will now be routed to the WSGI app instance.
+ return wsgiapp.WSGIApp(app, "proxapp", 80)
# SSL works too, but the magic domain needs to be resolvable from the mitmproxy machine due to mitmproxy's design.
# mitmproxy will connect to said domain and use serve its certificate (unless --no-upstream-cert is set)
# but won't send any data.
- mitmproxy.ctx.master.apps.add(app, "example.com", 443)
+ # mitmproxy.ctx.master.apps.add(app, "example.com", 443)
diff --git a/mitmproxy/builtins/wsgiapp.py b/mitmproxy/builtins/wsgiapp.py
index 266867c8..07ec8a6f 100644
--- a/mitmproxy/builtins/wsgiapp.py
+++ b/mitmproxy/builtins/wsgiapp.py
@@ -5,6 +5,10 @@ from netlib import version
class WSGIApp:
+ """
+ An addon that hosts a WSGI app withing mitproxy, at a specified
+ hostname and port.
+ """
def __init__(self, app, host, port):
self.app, self.host, self.port = app, host, port
diff --git a/test/mitmproxy/builtins/test_wsgiapp.py b/test/mitmproxy/builtins/test_wsgiapp.py
index c8991892..a39ec5c3 100644
--- a/test/mitmproxy/builtins/test_wsgiapp.py
+++ b/test/mitmproxy/builtins/test_wsgiapp.py
@@ -33,29 +33,9 @@ class TestApp(tservers.HTTPProxyTest):
ret = p.request("get:'http://testapp/'")
assert ret.status_code == 200
- def _test_app_err(self):
+ def test_app_err(self):
p = self.pathoc()
with p.connect():
ret = p.request("get:'http://errapp/'")
assert ret.status_code == 500
assert b"ValueError" in ret.content
-
-
-def _test_app_registry():
- ar = flow.AppRegistry()
- ar.add("foo", "domain", 80)
-
- r = HTTPRequest.wrap(netlib.tutils.treq())
- r.host = "domain"
- r.port = 80
- assert ar.get(r)
-
- r.port = 81
- assert not ar.get(r)
-
- r = HTTPRequest.wrap(netlib.tutils.treq())
- r.host = "domain2"
- r.port = 80
- assert not ar.get(r)
- r.headers["host"] = "domain"
- assert ar.get(r)