aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/web
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2014-09-17 13:58:56 +1200
committerAldo Cortesi <aldo@nullcube.com>2014-09-17 13:58:56 +1200
commitb4ecd96beb77a8bae02d82eac174dded198797a3 (patch)
tree1868202264b5e201338698b76dbed5104448ec28 /libmproxy/web
parent51db9a5612f0899ed61751dbee3f4e4b19a74ea4 (diff)
downloadmitmproxy-b4ecd96beb77a8bae02d82eac174dded198797a3.tar.gz
mitmproxy-b4ecd96beb77a8bae02d82eac174dded198797a3.tar.bz2
mitmproxy-b4ecd96beb77a8bae02d82eac174dded198797a3.zip
Introduce short form object state, and connect the ends to send data to web app
Diffstat (limited to 'libmproxy/web')
-rw-r--r--libmproxy/web/__init__.py15
-rw-r--r--libmproxy/web/app.py10
-rw-r--r--libmproxy/web/static/js/app.js10
3 files changed, 32 insertions, 3 deletions
diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py
index c2597861..50b41b80 100644
--- a/libmproxy/web/__init__.py
+++ b/libmproxy/web/__init__.py
@@ -81,18 +81,31 @@ class WebMaster(flow.FlowMaster):
self.shutdown()
def handle_request(self, f):
- pprint.pprint(f.get_state())
+ app.ClientConnection.broadcast("flow", f.get_state(True))
flow.FlowMaster.handle_request(self, f)
if f:
f.reply()
return f
def handle_response(self, f):
+ app.ClientConnection.broadcast("flow", f.get_state(True))
flow.FlowMaster.handle_response(self, f)
if f:
f.reply()
return f
def handle_error(self, f):
+ app.ClientConnection.broadcast("flow", f.get_state(True))
flow.FlowMaster.handle_error(self, f)
return f
+
+ def handle_log(self, l):
+ app.ClientConnection.broadcast(
+ "event", {
+ "message": l.msg,
+ "level": l.level
+ }
+ )
+ self.add_event(l.msg, l.level)
+ l.reply()
+
diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py
index e9bcc526..e2765a6d 100644
--- a/libmproxy/web/app.py
+++ b/libmproxy/web/app.py
@@ -2,6 +2,7 @@ import os.path
import tornado.web
import tornado.websocket
import logging
+import json
class IndexHandler(tornado.web.RequestHandler):
@@ -22,7 +23,14 @@ class ClientConnection(tornado.websocket.WebSocketHandler):
def broadcast(cls, type, data):
for conn in cls.connections:
try:
- conn.write_message(type, data)
+ conn.write_message(
+ json.dumps(
+ {
+ "type": type,
+ "data": data
+ }
+ )
+ )
except:
logging.error("Error sending message", exc_info=True)
diff --git a/libmproxy/web/static/js/app.js b/libmproxy/web/static/js/app.js
index 90a004ef..84eece87 100644
--- a/libmproxy/web/static/js/app.js
+++ b/libmproxy/web/static/js/app.js
@@ -221,7 +221,15 @@ _Connection.prototype.onopen = function (open) {
};
_Connection.prototype.onmessage = function (message) {
//AppDispatcher.dispatchServerAction(...);
- console.log("onmessage", this, arguments);
+ var m = JSON.parse(message.data);
+ switch (m.type){
+ case "flow":
+ console.log("flow", m.data);
+ break;
+ case "event":
+ console.log("event", m.data.message)
+ break;
+ }
};
_Connection.prototype.onerror = function (error) {
console.log("onerror", this, arguments);