aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-19 16:57:57 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-19 16:57:57 +1200
commit892ee2a9041166ca4ae1e35893174791b96cccfa (patch)
tree25008c40584a09c70457716934e4defecf0251d8 /libpathod
parenta700721891e028aacc867001a715a8f7d9cbf223 (diff)
downloadmitmproxy-892ee2a9041166ca4ae1e35893174791b96cccfa.tar.gz
mitmproxy-892ee2a9041166ca4ae1e35893174791b96cccfa.tar.bz2
mitmproxy-892ee2a9041166ca4ae1e35893174791b96cccfa.zip
Start porting web app to Flask.
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/app.py12
-rw-r--r--libpathod/pathod.py19
-rw-r--r--libpathod/test.py8
3 files changed, 31 insertions, 8 deletions
diff --git a/libpathod/app.py b/libpathod/app.py
index 8ea19f4c..95e7d169 100644
--- a/libpathod/app.py
+++ b/libpathod/app.py
@@ -1,4 +1,15 @@
+from flask import Flask, jsonify
+import version
+app = Flask(__name__)
+@app.route('/api/info')
+def api_info():
+ return jsonify(
+ version = version.IVERSION
+ )
+
+
+"""
class APILog(tornado.web.RequestHandler):
def get(self):
self.write(
@@ -95,3 +106,4 @@ class ClearLog(_Page):
def post(self):
self.application.clear_logs()
self.redirect("/log")
+"""
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index c700b550..c8608bd6 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -1,4 +1,6 @@
-from netlib import tcp, protocol, odict
+from netlib import tcp, protocol, odict, wsgi
+import version, app
+
class PathodHandler(tcp.BaseHandler):
def handle(self):
@@ -13,13 +15,24 @@ class PathodHandler(tcp.BaseHandler):
content = protocol.read_http_body_request(
self.rfile, self.wfile, headers, httpversion, None
)
- print method, path, httpversion
- #return flow.Request(client_conn, httpversion, host, port, "http", method, path, headers, content)
+ cc = wsgi.ClientConn(self.client_address)
+ req = wsgi.Request(cc, "http", method, path, headers, content)
+ sn = self.connection.getsockname()
+ app = wsgi.WSGIAdaptor(
+ self.server.app,
+ sn[0],
+ self.server.port,
+ version.NAMEVERSION
+ )
+ app.serve(req, self.wfile)
+
class Pathod(tcp.TCPServer):
def __init__(self, addr):
tcp.TCPServer.__init__(self, addr)
+ self.app = app.app
+ self.app.config["pathod"] = self
def handle_connection(self, request, client_address):
PathodHandler(request, client_address, self)
diff --git a/libpathod/test.py b/libpathod/test.py
index 28fcd664..f33e922f 100644
--- a/libpathod/test.py
+++ b/libpathod/test.py
@@ -7,10 +7,8 @@ IFACE = "127.0.0.1"
class Daemon:
def __init__(self, staticdir=None, anchors=(), ssl=None):
- #self.app = pathod.make_app(staticdir=staticdir, anchors=anchors)
- self.app = None
self.q = Queue.Queue()
- self.thread = PaThread(self.q, self.app, ssl)
+ self.thread = PaThread(self.q, ssl)
self.thread.start()
self.port = self.q.get(True, 5)
self.urlbase = "%s://%s:%s"%("https" if ssl else "http", IFACE, self.port)
@@ -25,9 +23,9 @@ class Daemon:
class PaThread(threading.Thread):
- def __init__(self, q, app, ssl):
+ def __init__(self, q, ssl):
threading.Thread.__init__(self)
- self.q, self.app, self.ssl = q, app, ssl
+ self.q, self.ssl = q, ssl
self.port = None
def run(self):