mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
add Reader.peek()
This commit is contained in:
parent
c92dc1b868
commit
62416daa4a
@ -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):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user