From f7bd690e3aba0be05c30a3b9a4d499de8dbd5e06 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 31 May 2015 17:18:55 +1200 Subject: [PATCH] When we see an incomplete read with 0 bytes, it's a disconnect Partially fixes mitmproxy/mitmproxy:#593 --- netlib/tcp.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/netlib/tcp.py b/netlib/tcp.py index c8545d4f2..f6179faa6 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -225,9 +225,12 @@ class Reader(_FileLike): """ result = self.read(length) if length != -1 and len(result) != length: - raise NetLibIncomplete( - "Expected %s bytes, got %s" % (length, len(result)) - ) + if not result: + raise NetLibDisconnect() + else: + raise NetLibIncomplete( + "Expected %s bytes, got %s" % (length, len(result)) + ) return result