proxy.plugin.mock_rest_api 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.mock_rest_api.ProposedRestApiPlugin(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.proxy.plugin.HttpProxyBasePlugin

Mock responses for your upstream REST API.

Used to test and develop client side applications without need of an actual upstream REST API server.

Returns proposed REST API mock responses to the client without establishing upstream connection.

Note: This plugin won’t work if your client is making HTTPS connection to api.example.com.

API_SERVER = b'api.example.com'#
REST_API_SPEC = {b'/v1/users/': {'count': 2, 'next': None, 'previous': None, 'results': [{'email': 'you@example.com', 'groups': [], 'url': 'api.example.com/v1/users/1/', 'username': 'admin'}, {'email': 'someone@example.com', 'groups': [], 'url': 'api.example.com/v1/users/2/', 'username': 'someone'}]}}#
_abc_impl = <_abc._abc_data object>#
before_upstream_connection(request: proxy.http.parser.parser.HttpParser) Optional[proxy.http.parser.parser.HttpParser][source]#

Handler called just before Proxy upstream connection is established.

Return optionally modified request object. If None is returned, upstream connection won’t be established.

Raise HttpRequestRejected or HttpProtocolException directly to drop the connection.

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

Handler called before dispatching client request to upstream.

Note: For pipelined (keep-alive) connections, this handler can be called multiple times, for each request sent to upstream.

Note: If TLS interception is enabled, this handler can be called multiple times if client exchanges multiple requests over same SSL session.

Return optionally modified request object to dispatch to upstream. Return None to drop the request data, e.g. in case a response has already been queued. Raise HttpRequestRejected or HttpProtocolException directly to tear down the connection with client.