diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-07-24 11:39:49 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-07-24 11:41:18 +1200 |
commit | 91752990d5863526745e5c31cfb4b7459d11047e (patch) | |
tree | 5309c036f76f78aac3056ed98935f0f766379994 /netlib/tcp.py | |
parent | eb88cea3c74a253d3a08d010bfd328aa845c6d5b (diff) | |
download | mitmproxy-91752990d5863526745e5c31cfb4b7459d11047e.tar.gz mitmproxy-91752990d5863526745e5c31cfb4b7459d11047e.tar.bz2 mitmproxy-91752990d5863526745e5c31cfb4b7459d11047e.zip |
Handle HTTP responses that have a body but no content-length or transfer encoding
We check if the server sent a connection:close header, and read till the socket
closes.
Closes #2
Diffstat (limited to 'netlib/tcp.py')
-rw-r--r-- | netlib/tcp.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py index 66a26872..7d3705da 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -40,6 +40,7 @@ class NetLibTimeout(Exception): pass class FileLike: + BLOCKSIZE = 1024 * 32 def __init__(self, o): self.o = o @@ -51,11 +52,14 @@ class FileLike: self.o.flush() def read(self, length): + """ + If length is None, we read until connection closes. + """ result = '' start = time.time() - while length > 0: + while length == -1 or length > 0: try: - data = self.o.read(length) + data = self.o.read(self.BLOCKSIZE if length == -1 else length) except SSL.ZeroReturnError: break except SSL.WantReadError: @@ -73,7 +77,8 @@ class FileLike: if not data: break result += data - length -= len(data) + if length != -1: + length -= len(data) return result def write(self, v): |