Documentation
¶
Overview ¶
Package plugin is the Culvert middleware plugin API: the Middleware contract, the process-wide plugin chain, and the panic-safe dispatch the proxy hot path calls. Extracted from package main per ADR-0002; the unqualified names (RegisterPlugin, pluginDecision, ...) remain available in main via the plugin.go alias shim.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OnResponse ¶
OnResponse notifies all plugins of a completed response.
func Register ¶
func Register(m Middleware)
Register appends a Middleware to the global plugin chain. Call this from init() or before the proxy starts.
Types ¶
type Decision ¶
type Decision int
Decision is the outcome of a plugin's OnRequest evaluation.
Decision values returned by Middleware.OnRequest.
type Middleware ¶
type Middleware interface {
// Name returns a human-readable identifier (used in logs).
Name() string
// OnRequest is called before each request is forwarded.
// Return DecisionBlock to reject; DecisionAllow to pass through.
OnRequest(clientIP, method, host string) Decision
// OnResponse is called after a successful upstream response.
// It may modify response headers. Called with nil if no response exists.
OnResponse(resp *http.Response)
}
Middleware is the interface all Culvert plugins must implement.
Example:
type MyPlugin struct{}
func (p *MyPlugin) Name() string { return "my-plugin" }
func (p *MyPlugin) OnRequest(ip, method, host string) Decision { return DecisionAllow }
func (p *MyPlugin) OnResponse(resp *http.Response) {}
Register with: RegisterPlugin(&MyPlugin{})
func Replace ¶
func Replace(ps []Middleware) []Middleware
Replace swaps the entire plugin chain and returns the previous one. Test support: pair the calls to restore the original chain. Not safe concurrently with traffic (the chain is read lock-free on the hot path).