A plugin is a custom component used to intercept and manipulate network traffic. To create one, you must create a subclass of spoa_python.plugins.Plugin and implement two mandatory methods: on_request and on_response.
Lifecycle and Arguments
Both methods receive the following shared context:
id: A transaction ID (string) that remains identical for both the request and the corresponding response.config: The PolicyConfig associated with the policy triggering the plugin.
Implementation Details
on_request: Triggered when a request matches a configured policy. It receives additional arguments describing the request: method, path, query, headers, and body.on_response: Triggered when a response is received. It receives additional arguments describing the response: status, headers, and body.
Each method must return an Action to determine how the Plugin Runner should proceed.
from spoa_python.plugins import Plugin
class MyPlugin(Plugin):
def on_request(self, id, config, method, path, query, headers, body):
# Logic for intercepting requests
return NoOpAction()
def on_response(self, id, config, status, headers, body):
# Logic for intercepting responses
return NoOpAction()