testproxy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 6 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

Overview

Package testproxy is a small TCP forwarder for tests: it sits between a client and a server and can add a delay to every chunk, cut the open connections and refuse new ones. Its listener is open from the start.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

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

Proxy forwards the connections that reach Addr to the target.

func Start

func Start(target string) (*Proxy, error)

Start listens on a free loopback port and forwards to target.

func (*Proxy) Addr

func (p *Proxy) Addr() string

Addr is the address clients dial.

func (*Proxy) Close

func (p *Proxy) Close()

Close stops the listener, closes every connection and waits for the goroutines.

func (*Proxy) Cut

func (p *Proxy) Cut()

Cut closes every open connection. New connections are still accepted.

func (*Proxy) SetDelay

func (p *Proxy) SetDelay(d time.Duration)

SetDelay adds d to every chunk that is forwarded, in both directions (zero: no delay). It applies to the open connections too, from the next chunk.

func (*Proxy) SetRefuse

func (p *Proxy) SetRefuse(refuse bool)

SetRefuse makes the proxy close every new connection at once while refuse is true, and cuts the open ones: the target went away and comes back with SetRefuse(false).

func (*Proxy) SetTarget

func (p *Proxy) SetTarget(target string)

SetTarget changes the address that new connections are forwarded to (a server that came back on another port).

Jump to

Keyboard shortcuts

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