plugin

package
v1.0.126 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 2 Imported by: 0

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

func OnResponse(resp *http.Response)

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.

const (
	DecisionAllow Decision = iota // pass request through
	DecisionBlock                 // reject the request
)

Decision values returned by Middleware.OnRequest.

func Decide

func Decide(clientIP, method, host string) Decision

Decide runs all plugins in order and returns DecisionBlock on the first plugin that blocks, or DecisionAllow if all pass. A panicking plugin is recovered and treated as a pass-through to avoid bringing down the proxy.

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL