aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol/__init__.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-01-30 05:00:13 +0100
committerMaximilian Hils <git@maximilianhils.com>2014-01-30 05:00:13 +0100
commit40bf42f14a7ec386024a8925502fa3c6e6f0657e (patch)
treedb4d76b903a170ba0315a1fc270b14bf9034f9ee /libmproxy/protocol/__init__.py
parent607f7778110d5c2720e60ffcf5f4b0c94e8fcc5f (diff)
downloadmitmproxy-40bf42f14a7ec386024a8925502fa3c6e6f0657e.tar.gz
mitmproxy-40bf42f14a7ec386024a8925502fa3c6e6f0657e.tar.bz2
mitmproxy-40bf42f14a7ec386024a8925502fa3c6e6f0657e.zip
merge flow classes. current status: basic mitmdump working
Diffstat (limited to 'libmproxy/protocol/__init__.py')
-rw-r--r--libmproxy/protocol/__init__.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/libmproxy/protocol/__init__.py b/libmproxy/protocol/__init__.py
new file mode 100644
index 00000000..5419c5ef
--- /dev/null
+++ b/libmproxy/protocol/__init__.py
@@ -0,0 +1,46 @@
+KILL = 0 # const for killed requests
+
+
+class ConnectionTypeChange(Exception):
+ """
+ Gets raised if the connetion type has been changed (e.g. after HTTP/1.1 101 Switching Protocols).
+ It's up to the raising ProtocolHandler to specify the new conntype before raising the exception.
+ """
+ pass
+
+
+class ProtocolHandler(object):
+ def __init__(self, c):
+ self.c = c
+
+ def handle_messages(self):
+ """
+ This method gets called if a client connection has been made. Depending on the proxy settings,
+ a server connection might already exist as well.
+ """
+ raise NotImplementedError
+
+ def handle_error(self, error):
+ """
+ This method gets called should there be an uncaught exception during the connection.
+ This might happen outside of handle_messages, e.g. if the initial SSL handshake fails in transparent mode.
+ """
+ raise NotImplementedError
+
+
+from .http import HTTPHandler
+
+
+def _handler(conntype, connection_handler):
+ if conntype == "http":
+ return HTTPHandler(connection_handler)
+
+ raise NotImplementedError
+
+
+def handle_messages(conntype, connection_handler):
+ return _handler(conntype, connection_handler).handle_messages()
+
+
+def handle_error(conntype, connection_handler, error):
+ return _handler(conntype, connection_handler).handle_error(error) \ No newline at end of file