proxy.plugin.proxy_pool module#

proxy.py#

⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.

copyright
  1. 2013-present by Abhinav Singh and contributors.

license

BSD, see LICENSE for more details.

class proxy.plugin.proxy_pool.ProxyPoolPlugin(*args: Any, **kwargs: Any)[source]#

Bases: proxy.core.base.tcp_upstream.TcpUpstreamConnectionHandler, proxy.http.proxy.plugin.HttpProxyBasePlugin

Proxy pool plugin simply acts as a proxy adapter for proxy.py itself.

Imagine this plugin as setting up proxy settings for proxy.py instance itself. All incoming client requests are proxied to configured upstream proxies.

_abc_impl = <_abc._abc_data object>#
_endpoint: Url#
_metadata: List[Any]#
_select_proxy() proxy.http.url.Url[source]#

Choose a random proxy from the pool.

TODO: Implement your own logic here e.g. round-robin, least connection etc.

access_log(log_attrs: Dict[str, Any]) None[source]#
before_upstream_connection(request: proxy.http.parser.parser.HttpParser) Optional[proxy.http.parser.parser.HttpParser][source]#

Avoids establishing the default connection to upstream server by returning None.

TODO(abhinavsingh): Ideally connection to upstream proxy endpoints must be bootstrapped within it’s own re-usable and garbage collected pool, to avoid establishing a new upstream proxy connection for each client request.

See UpstreamConnectionPool which is a work in progress for SSL cache handling.

handle_client_data(raw: memoryview) Optional[memoryview][source]#

Only invoked when before_upstream_connection returns None

handle_client_request(request: proxy.http.parser.parser.HttpParser) Optional[proxy.http.parser.parser.HttpParser][source]#

Only invoked once after client original proxy request has been received completely.

handle_upstream_chunk(chunk: memoryview) Optional[memoryview][source]#

Will never be called since we didn’t establish an upstream connection.

handle_upstream_data(raw: memoryview) None[source]#
on_access_log(context: Dict[str, Any]) Optional[Dict[str, Any]][source]#

Use this method to override default access log format (see DEFAULT_HTTP_ACCESS_LOG_FORMAT and DEFAULT_HTTPS_ACCESS_LOG_FORMAT) and to add/update/modify/delete context for next plugin.on_access_log invocation.

This is specially useful if a plugins want to provide extra context in the access log which may not available within other plugins’ context or even in proxy.py core.

Returns Log context or None. If plugin chooses to access log, they ideally must return None to prevent other plugin.on_access_log invocation.

on_upstream_connection_close() None[source]#

Called when client connection has been closed.

upstream: Optional[TcpServerConnection]#