Documentation
¶
Index ¶
Constants ¶
const ( MetaKeySid = "sid" MetaKeyDirection = "direction" MetaKeyURI = "uri" MetaKeyKind = "kind" )
Rewriter-plugin metadata common fields (JSON convention, opaque to core/plugin — carried in RewriteRequest.Metadata).
const ( KindBody = "body" KindHeader = "header" )
Kind values: what the plugin is receiving (byte payload vs header block).
const DefaultReadTimeout = 30 * time.Second
DefaultReadTimeout is the default timeout for reading data from connections.
Variables ¶
var DefaultCertPool = tls_util.NewMemoryCertPool()
DefaultCertPool is the default in-memory certificate pool used for TLS MITM.
Functions ¶
func Dispatch ¶ added in v0.28.1
func Dispatch(s *Sniffer, ctx context.Context, conn net.Conn, proto string, opts ...sniffing.HandleOption) (handled bool, err error)
Dispatch routes a detected protocol to its registered handler. It returns (false, nil) when no handler is registered for proto, signalling the caller to fall through to raw forwarding.
func Register ¶ added in v0.28.1
func Register(proto string, fn HandleFunc)
Register associates a protocol with its handler. Duplicate registration panics, mirroring the house registry pattern.
Types ¶
type HandleFunc ¶ added in v0.28.1
type HandleFunc func(s *Sniffer, ctx context.Context, conn net.Conn, opts ...sniffing.HandleOption) error
HandleFunc handles a connection whose protocol has been detected as proto, mirroring sniffing.HandleFunc but without the network parameter. The receiver s carries the per-connection Sniffer state.
func Get ¶ added in v0.28.1
func Get(proto string) (HandleFunc, bool)
Get returns the handler registered for proto.
type HandleOption ¶
type HandleOption = sniffing.HandleOption
HandleOption configures HandleOptions for sniffing handlers.
type HandleOptions ¶
type HandleOptions = sniffing.HandleOptions
HandleOptions aliases sniffing.HandleOptions, the unified option set shared by the sniffing and forwarder Sniffer implementations.
type Sniffer ¶
type Sniffer struct {
Websocket bool
WebsocketSampleRate float64
Recorder recorder.Recorder
RecorderOptions *recorder.Options
// MITM TLS termination
Certificate *x509.Certificate
PrivateKey crypto.PrivateKey
NegotiatedProtocol string
CertPool tls_util.CertPool
MitmBypass bypass.Bypass
// ReadTimeout is the deadline for reading the upstream response
// headers during HTTP sniffing (http.ReadResponse) and the TLS
// ServerHello during TLS sniffing. This timeout is applied once
// per request/response pair in the HTTP keep-alive loop and cleared
// after each response is received. It does NOT affect the client
// connection or the response body transfer.
// Default: DefaultReadTimeout (30s) if not set.
ReadTimeout time.Duration
// Cache, when non-nil, caches upstream HTTP responses. It is shared across
// connections (built once per service), so all connections referencing the
// same named cache share one store.
Cache *httpcache.Cache
}
Sniffer handles HTTP and TLS traffic sniffing, recording, and MITM TLS termination for protocol-aware forwarding. It can intercept HTTP requests, perform hop/node selection, apply bypass rules, rewrite URLs and response bodies, and terminate TLS for content inspection.
func (*Sniffer) HandleHTTP ¶
HandleHTTP sniffs and proxies an HTTP connection. It reads the initial request, performs node selection via the configured hop, and forwards the request with HTTP keep-alive support.
func (*Sniffer) HandleRedis ¶ added in v0.28.1
HandleRedis proxies a sniffed Redis connection through a hop-selected node. It parses the first RESP message for metadata recording, selects an upstream node via resolveRedisNode (which passes ProtoRedis to the hop's protocol selector), replays the captured bytes, and pipes traffic bidirectionally.