aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-07-25 13:31:04 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-18 21:08:01 +0200
commit62416daa4a3776563556fb45ef9bd749fb44c334 (patch)
treef3006adad3e4a4986245402668e77d669a31aa0b /netlib
parentc92dc1b8682ed15b68890f18c65b3f31122e9fa4 (diff)
downloadmitmproxy-62416daa4a3776563556fb45ef9bd749fb44c334.tar.gz
mitmproxy-62416daa4a3776563556fb45ef9bd749fb44c334.tar.bz2
mitmproxy-62416daa4a3776563556fb45ef9bd749fb44c334.zip
add Reader.peek()
Diffstat (limited to 'netlib')
-rw-r--r--netlib/tcp.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 22cd0965..b05e84f5 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -265,6 +265,24 @@ class Reader(_FileLike):
)
return result
+ def peek(self, length):
+ """
+ Tries to peek into the underlying file object.
+
+ Returns:
+ Up to the next N bytes if peeking is successful.
+ None, otherwise.
+
+ Raises:
+ NetLibSSLError if there was an error with pyOpenSSL.
+ """
+ if isinstance(self.o, SSL.Connection) or isinstance(self.o, socket._fileobject):
+ try:
+ return self.o._sock.recv(length, socket.MSG_PEEK)
+ except SSL.Error as e:
+ raise NetLibSSLError(str(e))
+
+
class Address(object):