proxy

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package proxy sits between a local client and one upstream service, forwards the exchange untouched, and hands a copy to the recorder.

Forwarding fidelity comes first. Sonda is a debugger: if it alters what the upstream receives or what the client sees, every conclusion drawn from it is worthless. Capture is a side effect of the copy, never a step in it.

Index

Constants

View Source
const FaultHeader = "X-Sonda-Fault"

FaultHeader marks an answer Sonda broke on purpose. Same role as the stub header: a client that cannot tell an injected failure from a real one would chase the wrong bug, and this is the one place the distinction reaches code that is not looking at Sonda's interface.

View Source
const ReplayHeader = "X-Sonda-Replay-Of"

ReplayHeader marks a request Sonda is sending on the operator's behalf. The proxy strips it before forwarding, so the upstream receives exactly the original request and the captured headers do not gain a field the real client never sent — the replay is recorded as a link, not as a difference in the traffic.

View Source
const StubHeader = "X-Sonda-Stub"

StubHeader goes on every answer that came from a recording rather than from the service. A client that cannot tell the two apart is the failure mode this whole feature has to avoid, and a header is the one place the distinction reaches code that is not looking at Sonda's interface.

Variables

This section is empty.

Functions

This section is empty.

Types

type Faults added in v0.9.0

type Faults interface {
	Next(target string) fault.Action
}

Faults is the part of the fault registry a proxy needs. Nil never injects anything, which is what every proxy does until told otherwise.

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

func New

func New(target config.Target, maxBody int64, recorder Recorder, stubs Stubs, faults Faults) *Proxy

func (*Proxy) Handler

func (p *Proxy) Handler() http.Handler

Handler is what the listener serves: the proxy itself for HTTP targets, and an h2c-capable wrapper for gRPC ones.

func (*Proxy) Serve

func (p *Proxy) Serve(ctx context.Context) error

Serve runs the proxy until ctx is cancelled.

func (*Proxy) ServeAMQP added in v0.16.0

func (p *Proxy) ServeAMQP(client net.Conn)

ServeAMQP forwards one AMQP 0-9-1 connection byte-for-byte and records useful units while the connection remains open.

One RabbitMQ connection commonly lives for hours and multiplexes many channels. Waiting for it to close would make a publish invisible while it is being debugged, and one row per frame would split a method from its content. The taps therefore emit standalone methods immediately and group each content-bearing method with its following header and body frames per channel.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Proxy) ServePostgres added in v0.11.0

func (p *Proxy) ServePostgres(client net.Conn)

ServePostgres forwards one client connection to the upstream database and records a capture per statement while it runs.

type Recorder

type Recorder interface {
	Record(*store.Call)
}

Recorder is the sink for captured calls. It is an interface so the proxy can be tested without a database.

type Stubs added in v0.6.0

type Stubs interface {
	On(target string) bool
	Match(ctx context.Context, target, method, path string, body []byte) (*store.Call, error)
}

Stubs is the part of the stub registry a proxy needs. Nil means this proxy always forwards, which is what every proxy does until someone says otherwise.

Jump to

Keyboard shortcuts

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