proxy.core.base package#
Submodules#
Module contents#
proxy.py#
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.
- copyright
2013-present by Abhinav Singh and contributors.
- license
BSD, see LICENSE for more details.
- class proxy.core.base.BaseTcpServerHandler(*args: Any, **kwargs: Any)[source]#
Bases:
proxy.core.work.work.Work
[proxy.core.base.tcp_server.T
]BaseTcpServerHandler implements Work interface.
BaseTcpServerHandler lifecycle is controlled by Threadless core using asyncio. If you want to also support threaded mode, also implement the optional run() method from Work class.
An instance of BaseTcpServerHandler is created for each client connection. BaseTcpServerHandler ensures that server is always ready to accept new data from the client. It also ensures, client is ready to accept new data before flushing data to it.
Most importantly, BaseTcpServerHandler ensures that pending buffers to the client are flushed before connection is closed.
Implementations must provide:
a. handle_data(data: memoryview) implementation b. Optionally, also implement other Work method e.g. initialize, is_inactive, shutdown
- _abc_impl = <_abc._abc_data object>#
- _optionally_wrap_socket(conn: socket.socket) Union[ssl.SSLSocket, socket.socket] [source]#
Attempts to wrap accepted client connection using provided certificates.
Shutdown and closes client connection upon error.
- async get_events() Dict[int, int] [source]#
Return sockets and events (read or write) that we are interested in.
- abstract handle_data(data: memoryview) Optional[bool] [source]#
Optionally return True to close client connection.
- class proxy.core.base.BaseTcpTunnelHandler(*args: Any, **kwargs: Any)[source]#
Bases:
proxy.core.base.tcp_server.BaseTcpServerHandler
[proxy.core.connection.client.TcpClientConnection
]BaseTcpTunnelHandler build on-top of BaseTcpServerHandler work class.
On-top of BaseTcpServerHandler implementation, BaseTcpTunnelHandler introduces an upstream TcpServerConnection and adds it to the core event loop when needed.
Currently, implementations must call connect_upstream from within handle_data. See HttpsConnectTunnelHandler for example usage.
- _abc_impl = <_abc._abc_data object>#
- static create(*args: Any) proxy.core.connection.client.TcpClientConnection [source]#
Implementations are responsible for creation of work objects from incoming args. This helps keep work core agnostic to creation of externally defined work class objects.
- async get_events() Dict[int, int] [source]#
Return sockets and events (read or write) that we are interested in.
- abstract handle_data(data: memoryview) Optional[bool] [source]#
Optionally return True to close client connection.
- async handle_events(readables: List[int], writables: List[int]) bool [source]#
Return True to shutdown work.
- class proxy.core.base.TcpUpstreamConnectionHandler(*args: Any, **kwargs: Any)[source]#
Bases:
abc.ABC
TcpUpstreamConnectionHandler
can be used to insert an upstream server connection lifecycle.Call
initialize_upstream
to initialize the upstream connection object. Then, directly useself.upstream
object within your class.See
ProxyPoolPlugin
for example usage.- _abc_impl = <_abc._abc_data object>#
- abstract handle_upstream_data(raw: memoryview) None [source]#