proxy.http.server.plugin 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.http.server.plugin.HttpWebServerBasePlugin(uid: str, flags: argparse.Namespace, client: proxy.http.connection.HttpClientConnection, event_queue: proxy.core.event.queue.EventQueue, upstream_conn_pool: Optional[UpstreamConnectionPool] = None)[source]#

Bases: proxy.http.descriptors.DescriptorsHandlerMixin, abc.ABC

Web Server Plugin for routing of requests.

_abc_impl = <_abc._abc_data object>#
do_upgrade(request: proxy.http.parser.parser.HttpParser) bool[source]#
abstract handle_request(request: proxy.http.parser.parser.HttpParser) None[source]#

Handle the request and serve response.

name() str[source]#

A unique name for your plugin.

Defaults to name of the class. This helps plugin developers to directly access a specific plugin by its name.

on_access_log(context: Dict[str, Any]) Optional[Dict[str, Any]][source]#

Use this method to override default access log format (see DEFAULT_WEB_ACCESS_LOG_FORMAT) or to add/update/modify passed context for usage by default access logger.

Return updated log context to use for default logging format, OR Return None if plugin has logged the request.

on_client_connection_close() None[source]#

Client has closed the connection, do any clean up task now.

on_client_data(request: proxy.http.parser.parser.HttpParser, raw: memoryview) Optional[memoryview][source]#

Return None to avoid default webserver parsing of client data.

on_websocket_message(frame: proxy.http.websocket.frame.WebsocketFrame) None[source]#

Handle websocket frame.

on_websocket_open() None[source]#

Called when websocket handshake has finished.

abstract routes() List[Tuple[int, str]][source]#

Return List(protocol, path) that this plugin handles.

static serve_static_file(path: str, min_compression_length: int) memoryview[source]#
class proxy.http.server.plugin.ReverseProxyBasePlugin(uid: str, flags: argparse.Namespace, client: proxy.http.connection.HttpClientConnection, event_queue: proxy.core.event.queue.EventQueue, upstream_conn_pool: Optional[UpstreamConnectionPool] = None)[source]#

Bases: proxy.http.descriptors.DescriptorsHandlerMixin, abc.ABC

ReverseProxy base plugin class.

_abc_impl = <_abc._abc_data object>#
before_routing(request: proxy.http.parser.parser.HttpParser) Optional[proxy.http.parser.parser.HttpParser][source]#

Plugins can modify request, return response, close connection.

If None is returned, request will be dropped and closed.

handle_route(request: proxy.http.parser.parser.HttpParser, pattern: proxy.common.types.RePattern) Union[memoryview, proxy.http.url.Url, TcpServerConnection][source]#

Implement this method if you have configured dynamic routes.

on_access_log(context: Dict[str, Any]) Optional[Dict[str, Any]][source]#

Use this method to override default access log format (see DEFAULT_REVERSE_PROXY_ACCESS_LOG_FORMAT) or to add/update/modify passed context for usage by default access logger.

Return updated log context to use for default logging format, OR Return None if plugin has logged the request.

protocols() List[int][source]#
regexes() List[str][source]#

Helper method to return list of route regular expressions.

abstract routes() List[Union[str, Tuple[str, List[bytes]]]][source]#

List of routes registered by plugin.

There are 2 types of routes:

  1. Dynamic routes (str): Should be a regular expression

  2. Static routes (tuple): Contain 2 elements, a route regular expression and list of upstream urls to serve when the route matches.

Static routes doesn’t require you to implement the handle_route method. Reverse proxy core will automatically pick one of the configured upstream URL and serve it out-of-box.

Dynamic routes are helpful when you want to dynamically match and serve upstream urls. To handle dynamic routes, you must implement the handle_route method, which must return the url to serve.