diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2014-09-17 09:40:25 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2014-09-17 09:40:25 +1200 |
commit | f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63 (patch) | |
tree | 956984514258b8ebde4548b2032202447ee37dc7 /libmproxy/web/app.py | |
parent | 4f56b76b2c811006045c3226848aa5e122fb36ab (diff) | |
download | mitmproxy-f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63.tar.gz mitmproxy-f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63.tar.bz2 mitmproxy-f7da58ca9b8b3dc33f5a9b57999b07f99db5bc63.zip |
Basic websocket connection, code cleanup.
Diffstat (limited to 'libmproxy/web/app.py')
-rw-r--r-- | libmproxy/web/app.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 31b299a3..e9bcc526 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -1,6 +1,7 @@ - import os.path import tornado.web +import tornado.websocket +import logging class IndexHandler(tornado.web.RequestHandler): @@ -8,10 +9,29 @@ class IndexHandler(tornado.web.RequestHandler): self.render("index.html") +class ClientConnection(tornado.websocket.WebSocketHandler): + connections = set() + + def open(self): + ClientConnection.connections.add(self) + + def on_close(self): + ClientConnection.connections.remove(self) + + @classmethod + def broadcast(cls, type, data): + for conn in cls.connections: + try: + conn.write_message(type, data) + except: + logging.error("Error sending message", exc_info=True) + + class Application(tornado.web.Application): def __init__(self, debug): handlers = [ (r"/", IndexHandler), + (r"/updates", ClientConnection), ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), |