importsocketfromcontextlibimportcontextmanagerimportrequestsfromsocketimportSocketIOas_SocketIO@contextmanagerdefhook_socket_context():buffer=[]classSocketIO(_SocketIO):defreadinto(self,b):print('hooking')res=super().readinto(b)ifres>0:buffer.append(bytes(b[:res]))returnressocket.SocketIO=SocketIOyieldbuffersocket.SocketIO=_SocketIOwithhook_socket_context()asbuf:requests.get('https://v2ex.com/t/607316#reply10')print(b''.join(buf))print('with out hook')requests.get('https://v2ex.com/t/607316#reply10')print('done!')
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.