mitmproxy_rs

 1import sys
 2import types
 3
 4from .mitmproxy_rs import *
 5
 6__doc__ = mitmproxy_rs.__doc__
 7if hasattr(mitmproxy_rs, "__all__"):
 8    __all__ = mitmproxy_rs.__all__
 9
10# Hacky workaround for https://github.com/PyO3/pyo3/issues/759
11for k, v in vars(mitmproxy_rs).items():
12    if isinstance(v, types.ModuleType):
13        sys.modules[f"mitmproxy_rs.{k}"] = v
class Stream:

An individual TCP or UDP stream with an API that is similar to asyncio.StreamReader and asyncio.StreamWriter from the Python standard library.

async def read(self, n: int) -> bytes:

Read up to n bytes of a TCP stream, or a single UDP packet (n is ignored for UDP).

Return an empty bytes object if the connection was closed or the server has been shut down.

def write(self, data: bytes):

Write bytes onto the TCP stream, or send a single UDP packet.

For TCP, this queues the data into a write buffer. To wait until the stream can be written to again, await Stream.drain.

Raises: OSError if the connection has previously been closed or if server has been shut down.

async def drain(self) -> None:

Wait until the stream can be written to again.

Raises: OSError if the stream is closed or the server has been shut down.

def write_eof(self):

Close the TCP stream after flushing the write buffer. This method is a no-op for UDP streams, but may still raise an error (see below).

Raises: OSError if the server has been shut down.

def close(self):

Close the stream for both reading and writing.

Raises: OSError if the server has been shut down.

def is_closing(self) -> bool:

Check whether this stream is being closed.

async def wait_closed(self) -> None:

Wait until the stream is closed (currently a no-op).

def get_extra_info(*args, **kwds):

Query the stream for details of the underlying network connection.

Supported values:

  • Always available: transport_protocol, peername, sockname
  • WireGuard mode: original_dst, original_src
  • Local redirector mode: pid, process_name, remote_endpoint