faultproxy

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package faultproxy is an HTTP proxy that live tests put in front of a backend (a container such as Helix, an S3 server or Azurite) to fail its traffic at the network. With no rule set, the proxy forwards every request. A rule makes it refuse, reset, cut a response in the middle of its body, hang, or answer with a status and body of its own, for every request or for the requests that match.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fault

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

Fault is what the proxy does with a matched request.

func Answer

func Answer(status int, body string) Fault

Answer answers with status and body, and does not forward the request.

func Cut

func Cut(n int64) Fault

Cut forwards the request, sends the response headers and the first n bytes of the body, then closes the connection. The client reads an unexpected EOF in the middle of the body.

func Hang

func Hang() Fault

Hang holds the request and does not answer until the client stops waiting.

func Refuse

func Refuse() Fault

Refuse closes the connection before it answers. The client reads EOF.

func Reset

func Reset() Fault

Reset closes the connection with a TCP reset before it answers. The client reads "connection reset by peer".

type Proxy

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

Proxy forwards to one backend and applies the rule that is set.

func Start

func Start(t testing.TB, target *url.URL) *Proxy

Start starts a proxy in front of target, the backend's base URL. The proxy stops when t ends.

func (*Proxy) Clear

func (p *Proxy) Clear()

Clear removes the rule: the proxy forwards every request again.

func (*Proxy) ServeHTTP

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

ServeHTTP applies the rule to r, or forwards it.

func (*Proxy) Set

func (p *Proxy) Set(r Rule)

Set replaces the rule.

func (*Proxy) URL

func (p *Proxy) URL() string

URL is the base URL a client uses in place of the backend's.

type Rule

type Rule struct {
	// Match chooses the requests. Nil matches every request. Match can read
	// the request body: the proxy gives the body again to the backend.
	Match func(*http.Request) bool
	Fault Fault
	// Once applies the fault to one request only, then clears the rule.
	Once bool
}

Rule chooses the requests that get a fault.

Jump to

Keyboard shortcuts

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