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
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.
- 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>#
- handle_request(request: proxy.http.parser.parser.HttpParser) None [source]#
Handle the request and serve response.
- 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>#
- 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.
- class proxy.http.server.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:
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: re.Pattern[Any]) proxy.http.url.Url [source]#
Implement this method if you have configured dynamic routes.
- abstract routes() List[Union[str, Tuple[str, List[bytes]]]] [source]#
List of routes registered by plugin.
There are 2 types of routes:
Dynamic routes (str): Should be a regular expression
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.