aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/tcp.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-10-09 16:25:15 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-10-09 16:25:15 +1300
commit77869634e20ae5a2646d7455e499866e9cfafbab (patch)
tree17bdda510637aeeb29a1c6381fb89bbaf6b2408f /netlib/tcp.py
parent15679e010d99def2fb7efd1de5533099a12772ca (diff)
downloadmitmproxy-77869634e20ae5a2646d7455e499866e9cfafbab.tar.gz
mitmproxy-77869634e20ae5a2646d7455e499866e9cfafbab.tar.bz2
mitmproxy-77869634e20ae5a2646d7455e499866e9cfafbab.zip
Limit reads to block length.
Diffstat (limited to 'netlib/tcp.py')
-rw-r--r--netlib/tcp.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 414c1237..f8f877de 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -106,13 +106,17 @@ class Writer(_FileLike):
class Reader(_FileLike):
def read(self, length):
"""
- If length is None, we read until connection closes.
+ If length is -1, we read until connection closes.
"""
result = ''
start = time.time()
while length == -1 or length > 0:
+ if length == -1 or length > self.BLOCKSIZE:
+ rlen = self.BLOCKSIZE
+ else:
+ rlen = length
try:
- data = self.o.read(self.BLOCKSIZE if length == -1 else length)
+ data = self.o.read(rlen)
except SSL.ZeroReturnError:
break
except SSL.WantReadError: