diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2014-09-17 11:35:14 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2014-09-17 11:41:42 +1200 |
commit | d998790c2f12594e6d0edc5a98e908677b60b31f (patch) | |
tree | 2c9de7840374297d466eabf7670e87ab943e059f /libmproxy/protocol/tcp.py | |
parent | b9531ac89ba70d8404444d4e2b86b94153a783c9 (diff) | |
download | mitmproxy-d998790c2f12594e6d0edc5a98e908677b60b31f.tar.gz mitmproxy-d998790c2f12594e6d0edc5a98e908677b60b31f.tar.bz2 mitmproxy-d998790c2f12594e6d0edc5a98e908677b60b31f.zip |
Clean up and clarify StateObject
- Flatten the class hierarchy
- get_state, load_state, from_state are public
- Simplify code
- Remove __eq__ and __neq__. This fundamentally changes the semantics of
inherited objects in a way that's not part of the core function of the
class
Diffstat (limited to 'libmproxy/protocol/tcp.py')
-rw-r--r-- | libmproxy/protocol/tcp.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/libmproxy/protocol/tcp.py b/libmproxy/protocol/tcp.py index 990c502a..a56bf07b 100644 --- a/libmproxy/protocol/tcp.py +++ b/libmproxy/protocol/tcp.py @@ -1,8 +1,10 @@ from __future__ import absolute_import -import select, socket +import select +import socket from .primitives import ProtocolHandler from netlib.utils import cleanBin + class TCPHandler(ProtocolHandler): """ TCPHandler acts as a generic TCP forwarder. @@ -34,7 +36,9 @@ class TCPHandler(ProtocolHandler): closed = False if src.ssl_established: # Unfortunately, pyOpenSSL lacks a recv_into function. - contents = src.rfile.read(1) # We need to read a single byte before .pending() becomes usable + # We need to read a single byte before .pending() + # becomes usable + contents = src.rfile.read(1) contents += src.rfile.read(src.connection.pending()) if not contents: closed = True @@ -56,15 +60,30 @@ class TCPHandler(ProtocolHandler): continue if src.ssl_established or dst.ssl_established: - # 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. + # 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. contents = buf[:size].tobytes() - self.c.log("%s %s\r\n%s" % (direction, dst_str, cleanBin(contents)), "debug") + self.c.log( + "%s %s\r\n%s" % ( + direction, dst_str, cleanBin(contents) + ), + "debug" + ) 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") + self.c.log( + "%s %s\r\n%s" % ( + direction, + dst_str, + cleanBin(buf.tobytes()) + ), + "debug" + ) dst.connection.send(buf[:size]) except socket.error as e: self.c.log("TCP connection closed unexpectedly.", "debug") - return
\ No newline at end of file + return |