forwarder

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 51 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MetaKeySid       = "sid"
	MetaKeyDirection = "direction"
	MetaKeyURI       = "uri"
	MetaKeyKind      = "kind"
)

Rewriter-plugin metadata common fields (JSON convention, opaque to core/plugin — carried in RewriteRequest.Metadata).

View Source
const (
	KindBody   = "body"
	KindHeader = "header"
)

Kind values: what the plugin is receiving (byte payload vs header block).

View Source
const DefaultReadTimeout = 30 * time.Second

DefaultReadTimeout is the default timeout for reading data from connections.

Variables

View Source
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

func (h *Sniffer) HandleHTTP(ctx context.Context, conn net.Conn, opts ...HandleOption) error

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

func (h *Sniffer) HandleRedis(ctx context.Context, conn net.Conn, opts ...HandleOption) error

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.

func (*Sniffer) HandleTLS

func (h *Sniffer) HandleTLS(ctx context.Context, conn net.Conn, opts ...HandleOption) error

HandleTLS sniffs and proxies a TLS connection. It parses the ClientHello for SNI-based routing, optionally performs MITM TLS termination for HTTP content inspection, and records TLS handshake metadata.

Jump to

Keyboard shortcuts

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