proxy

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProxyTransport

func ProxyTransport(skipVerify bool, upstreamProxy string) (*http.Transport, error)

func ServeSocks5 added in v2.7.0

func ServeSocks5(addr, proxyAddr, auth string, allowNets []*net.IPNet, log *slog.Logger) error

forwards SOCKS5 CONNECT internally through the snare HTTP proxy at proxyAddr

Types

type BodyRewrite

type BodyRewrite struct {
	Pattern     *regexp.Regexp
	Replacement []byte
}

type Handler

type Handler struct {
	Transport        *http.Transport
	Store            *capture.Store
	Mocks            *mock.Store
	Intercept        *intercept.Queue
	InterceptMatch   string
	InterceptTimeout time.Duration
	HostCerts        *cert.HostCertCache
	Log              *slog.Logger
	MitmEnable       bool
	HostRewrites     []HostRewrite
	AddHeaders       []HeaderValue
	RemoveHeaders    []string
	OnCapture        func(*capture.Capture)
	IgnorePatterns   []string
	Scope            *ScopeStore
	MapRemotes       []MapRemoteRule
	BodyRewrites     []BodyRewrite
	MaxBodySize      int64
	Mode             string
	ReverseTarget    *url.URL
	Delay            time.Duration
	ChaosRate        float64
	Shadows          []*url.URL
	Plugins          []string
	ProtoDecoder     *ProtoDecoder
	Hooks            *HookEngine
	Auth             string
	AllowNets        []*net.IPNet
}

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type HeaderValue

type HeaderValue struct {
	Key   string
	Value string
}

type HookEngine added in v2.2.0

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

HookEngine runs JS hook files per request/response/capture. All methods are no-ops on a nil receiver.

func NewHookEngine added in v2.2.0

func NewHookEngine(files []string, log *slog.Logger) *HookEngine

func (*HookEngine) RunOnCapture added in v2.2.0

func (h *HookEngine) RunOnCapture(c *capture.Capture)

func (*HookEngine) RunOnRequest added in v2.2.0

func (h *HookEngine) RunOnRequest(req *http.Request, body []byte) (*HookShortCircuit, []byte)

func (*HookEngine) RunOnResponse added in v2.2.0

func (h *HookEngine) RunOnResponse(reqMethod, reqURL string, statusCode *int, headers http.Header, body []byte) []byte

type HookShortCircuit added in v2.2.0

type HookShortCircuit struct {
	Status  int
	Headers map[string]string
	Body    string
}

HookShortCircuit is returned when onRequest returns a response object, meaning the origin should not be contacted.

type HostRewrite

type HostRewrite struct {
	From string
	To   string
}

type MapRemoteRule

type MapRemoteRule struct {
	SourceHost string
	TargetBase *url.URL
}

type ProtoDecoder added in v2.1.0

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

ProtoDecoder holds parsed proto file descriptors for runtime gRPC decoding.

func NewProtoDecoder added in v2.1.0

func NewProtoDecoder(protoFiles []string) (*ProtoDecoder, error)

NewProtoDecoder parses the given .proto files and indexes every RPC method by its gRPC path (/package.Service/Method) for later message decoding.

func (*ProtoDecoder) DecodeRequest added in v2.1.0

func (d *ProtoDecoder) DecodeRequest(serviceMethod string, data []byte) (json.RawMessage, error)

func (*ProtoDecoder) DecodeResponse added in v2.1.0

func (d *ProtoDecoder) DecodeResponse(serviceMethod string, data []byte) (json.RawMessage, error)

type ScopeStore added in v2.5.0

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

func NewScopeStore added in v2.5.0

func NewScopeStore(patterns []string) *ScopeStore

func (*ScopeStore) Add added in v2.5.0

func (s *ScopeStore) Add(p string)

func (*ScopeStore) Get added in v2.5.0

func (s *ScopeStore) Get() []string

func (*ScopeStore) Remove added in v2.5.0

func (s *ScopeStore) Remove(p string)

type Server

type Server struct {
	*http.Server
	Listener net.Listener
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr string, handler http.Handler, log *slog.Logger) (*Server, error)

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Start

func (s *Server) Start()

func (*Server) StartH3 added in v2.1.0

func (s *Server) StartH3(handler http.Handler, tlsCfg *tls.Config, log *slog.Logger)

StartH3 starts an HTTP/3 (QUIC) server on the same address as the TCP server. tlsCfg must include at least one certificate (or GetCertificate). The TLS config is wrapped with the QUIC ALPN identifiers by quic-go automatically.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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