proxy.http.server package#

Submodules#

Module contents#

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.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>#
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_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.HttpWebServerPacFilePlugin(*args: Any, **kwargs: Any)[source]#

Bases: proxy.http.server.plugin.HttpWebServerBasePlugin

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

Handle the request and serve response.

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

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

class proxy.http.server.HttpWebServerPlugin(*args: Any, **kwargs: Any)[source]#

Bases: proxy.http.plugin.HttpProtocolHandlerPlugin

HttpProtocolHandler plugin which handles incoming requests to local web server.

_abc_impl = <_abc._abc_data object>#
_initialize_web_plugins() None[source]#
property _protocol: Tuple[bool, int]#
_try_route(path: bytes) bool[source]#
_try_static_or_404(path: bytes) None[source]#
access_log(context: Dict[str, Any]) None[source]#
encryption_enabled() bool[source]#
async get_descriptors() Tuple[List[int], List[int]][source]#

Implementations must return a list of descriptions that they wish to read from and write into.

on_client_connection_close() None[source]#

Client connection shutdown has been received, flush has been called, perform any cleanup work here.

on_client_data(raw: memoryview) None[source]#

Called only after original request has been completely received.

on_request_complete() Union[socket.socket, bool][source]#

Called right after client request parser has reached COMPLETE state.

on_response_chunk(chunk: List[memoryview]) List[memoryview][source]#

Handle data chunks as received from the server.

Return optionally modified chunk to return back to client.

static protocols() List[int][source]#
async read_from_descriptors(r: List[int]) bool[source]#

Implementations must now read data over the socket.

switch_to_websocket() None[source]#
async write_to_descriptors(w: List[int]) bool[source]#

Implementations must now write/flush data over the socket.

Note that buffer management is in-build into the connection classes. Hence implementations MUST call flush() here, to send any buffered data over the socket.

class proxy.http.server.ReverseProxyBasePlugin[source]#

Bases: abc.ABC

ReverseProxy base plugin class.

_abc_impl = <_abc._abc_data object>#
handle_route(request: proxy.http.parser.parser.HttpParser, pattern: re.Pattern[Any]) proxy.http.url.Url[source]#

Implement this method if you have configured dynamic routes.

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.