aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/web/__init__.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2014-09-14 11:30:00 +1200
committerAldo Cortesi <aldo@nullcube.com>2014-09-14 11:30:00 +1200
commit81e3a6e8e661b212bf45fb37623556f2793d2184 (patch)
treef0fdb3d88bce83263fa91b5a0000093f335d865f /libmproxy/web/__init__.py
parent7b74d207f39e642e5029a4855da47314ce224a33 (diff)
downloadmitmproxy-81e3a6e8e661b212bf45fb37623556f2793d2184.tar.gz
mitmproxy-81e3a6e8e661b212bf45fb37623556f2793d2184.tar.bz2
mitmproxy-81e3a6e8e661b212bf45fb37623556f2793d2184.zip
Super-basic outline for web io loop
Diffstat (limited to 'libmproxy/web/__init__.py')
-rw-r--r--libmproxy/web/__init__.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py
new file mode 100644
index 00000000..0ae155ef
--- /dev/null
+++ b/libmproxy/web/__init__.py
@@ -0,0 +1,88 @@
+
+import tornado.ioloop
+from .. import controller, utils, flow, script, proxy
+
+
+class Stop(Exception):
+ pass
+
+
+class WebState(flow.State):
+ def __init__(self):
+ flow.State.__init__(self)
+
+
+class Options(object):
+ attributes = [
+ "app",
+ "app_domain",
+ "app_ip",
+ "anticache",
+ "anticomp",
+ "client_replay",
+ "eventlog",
+ "keepserving",
+ "kill",
+ "intercept",
+ "no_server",
+ "refresh_server_playback",
+ "rfile",
+ "scripts",
+ "showhost",
+ "replacements",
+ "rheaders",
+ "setheaders",
+ "server_replay",
+ "stickycookie",
+ "stickyauth",
+ "stream_large_bodies",
+ "verbosity",
+ "wfile",
+ "nopop",
+ ]
+
+ def __init__(self, **kwargs):
+ for k, v in kwargs.items():
+ setattr(self, k, v)
+ for i in self.attributes:
+ if not hasattr(self, i):
+ setattr(self, i, None)
+
+
+class WebMaster(flow.FlowMaster):
+ def __init__(self, server, options):
+ flow.FlowMaster.__init__(self, server, WebState())
+
+ def tick(self):
+ flow.FlowMaster.tick(self, self.masterq, timeout=0)
+
+ def run(self): # pragma: no cover
+ self.server.start_slave(
+ controller.Slave,
+ controller.Channel(self.masterq, self.should_exit)
+ )
+ iol = tornado.ioloop.IOLoop.instance()
+ tornado.ioloop.PeriodicCallback(self.tick, 5).start()
+ try:
+ iol.start()
+ except (Stop, KeyboardInterrupt):
+ self.shutdown()
+
+ def handle_request(self, f):
+ print "req"
+ flow.FlowMaster.handle_request(self, f)
+ if f:
+ f.reply()
+ return f
+
+ def handle_response(self, f):
+ print "resp"
+ flow.FlowMaster.handle_response(self, f)
+ if f:
+ f.reply()
+ return f
+
+ def handle_error(self, f):
+ print "err"
+ flow.FlowMaster.handle_error(self, f)
+ return f