mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Limit reads to block length.
This commit is contained in:
parent
15679e010d
commit
77869634e2
@ -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:
|
||||
|
@ -255,6 +255,17 @@ class TestTCPClient:
|
||||
|
||||
|
||||
class TestFileLike:
|
||||
def test_blocksize(self):
|
||||
s = cStringIO.StringIO("1234567890abcdefghijklmnopqrstuvwxyz")
|
||||
s = tcp.Reader(s)
|
||||
s.BLOCKSIZE = 2
|
||||
assert s.read(1) == "1"
|
||||
assert s.read(2) == "23"
|
||||
assert s.read(3) == "456"
|
||||
assert s.read(4) == "7890"
|
||||
d = s.read(-1)
|
||||
assert d.startswith("abc") and d.endswith("xyz")
|
||||
|
||||
def test_wrap(self):
|
||||
s = cStringIO.StringIO("foobar\nfoobar")
|
||||
s.flush()
|
||||
|
Loading…
Reference in New Issue
Block a user