aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol/tcp.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-10-18 18:29:35 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-10-18 18:29:35 +0200
commite1148584380058f264b7aa7e9493115e4e8f2bbe (patch)
treed90acc5576e36808a1dea9907fe0b92130c45292 /libmproxy/protocol/tcp.py
parent52b29d49264e1397db6c65ee773479391b3fd37a (diff)
downloadmitmproxy-e1148584380058f264b7aa7e9493115e4e8f2bbe.tar.gz
mitmproxy-e1148584380058f264b7aa7e9493115e4e8f2bbe.tar.bz2
mitmproxy-e1148584380058f264b7aa7e9493115e4e8f2bbe.zip
add generic tcp proxying, fix #374
Diffstat (limited to 'libmproxy/protocol/tcp.py')
-rw-r--r--libmproxy/protocol/tcp.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/libmproxy/protocol/tcp.py b/libmproxy/protocol/tcp.py
index a56bf07b..da0c9087 100644
--- a/libmproxy/protocol/tcp.py
+++ b/libmproxy/protocol/tcp.py
@@ -13,6 +13,10 @@ class TCPHandler(ProtocolHandler):
chunk_size = 4096
+ def __init__(self, c, log=True):
+ super(TCPHandler, self).__init__(c)
+ self.log = log
+
def handle_messages(self):
self.c.establish_server_connection()
@@ -63,26 +67,25 @@ class TCPHandler(ProtocolHandler):
# if one of the peers is over SSL, we need to send
# bytes/strings
if not src.ssl_established:
- # only ssl to dst, i.e. we revc'd into buf but need
- # bytes/string now.
+ # we revc'd into buf but need bytes/string now.
contents = buf[:size].tobytes()
- self.c.log(
- "%s %s\r\n%s" % (
- direction, dst_str, cleanBin(contents)
- ),
- "debug"
- )
+ if self.log:
+ self.c.log(
+ "%s %s\r\n%s" % (
+ direction, dst_str, cleanBin(contents)
+ ),
+ "info"
+ )
dst.connection.send(contents)
else:
# socket.socket.send supports raw bytearrays/memoryviews
- self.c.log(
- "%s %s\r\n%s" % (
- direction,
- dst_str,
- cleanBin(buf.tobytes())
- ),
- "debug"
- )
+ if self.log:
+ self.c.log(
+ "%s %s\r\n%s" % (
+ direction, dst_str, cleanBin(buf.tobytes())
+ ),
+ "info"
+ )
dst.connection.send(buf[:size])
except socket.error as e:
self.c.log("TCP connection closed unexpectedly.", "debug")