proxy.plugin.reverse_proxy 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.reverse_proxy.ReverseProxyPlugin(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.server.plugin.ReverseProxyBasePlugin

This example plugin is equivalent to following Nginx configuration:

```text
location /get {
    proxy_pass http://httpbin.org/get
}
```

Plugin also demonstrates how to write “Python” equivalent for any “Nginx Lua” based configuration i.e. your plugin code will have full control over what do after one of your route has matched.

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

For our example dynamic route, we want to simply convert any incoming request to “/get/1” into “/get?id=1” when serving from upstream.

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.