proxy

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFlushInterval = 5 * time.Second

DefaultFlushInterval is how often the session file is synced to disk while the proxy is running.

View Source
const DefaultMaxBodyBytes int64 = 10 << 20 // 10 MiB

DefaultMaxBodyBytes is the default capture limit for response bodies.

Variables

This section is empty.

Functions

func TransactionInterceptor

func TransactionInterceptor(storage Storage) func(APITransaction)

TransactionInterceptor creates a function to intercept and store API transactions

Types

type APIInterceptor

type APIInterceptor func(APITransaction)

APIInterceptor is a function that processes API transactions

type APITransaction

type APITransaction struct {
	Request  RequestData
	Response ResponseData
	// ResponseTruncated is true when the captured response body was cut at
	// the proxy's capture limit; the full response was still forwarded.
	ResponseTruncated bool `json:"response_truncated,omitempty"`
}

APITransaction represents a complete API transaction (request + response)

type FileStorage

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

FileStorage stores API transactions as JSON files

func NewFileStorage

func NewFileStorage(baseDir string) (*FileStorage, error)

NewFileStorage creates a new file storage

func NewFileStorageReader added in v1.1.0

func NewFileStorageReader(baseDir string) (*FileStorage, error)

NewFileStorageReader creates a read-only view of a data directory. Unlike NewFileStorage it does not create a session file, so generation can read captured data without mutating the directory. Store and Clear return an error; Close is a no-op.

func NewFileStorageWithFlushInterval added in v1.1.0

func NewFileStorageWithFlushInterval(baseDir string, flushInterval time.Duration) (*FileStorage, error)

NewFileStorageWithFlushInterval creates a new file storage that syncs the session file to disk every flushInterval. An interval <= 0 disables periodic syncing; the file is still synced on Close.

func (*FileStorage) Clear

func (s *FileStorage) Clear() error

Clear removes all stored API transactions

func (*FileStorage) Close added in v1.1.0

func (s *FileStorage) Close() error

Close finalizes the session file

func (*FileStorage) GetAll

func (s *FileStorage) GetAll() ([]APITransaction, error)

GetAll returns all stored API transactions

func (*FileStorage) Store

func (s *FileStorage) Store(transaction APITransaction) error

Store saves an API transaction to storage

type ProxyServer

type ProxyServer struct {

	// MaxBodyBytes bounds how much of a response body is captured. The full
	// response is still forwarded to the client. <= 0 means unlimited.
	MaxBodyBytes int64
	// contains filtered or unexported fields
}

ProxyServer is an HTTP proxy server that captures API traffic

func NewProxyServer

func NewProxyServer(port int, target string, interceptor APIInterceptor) (*ProxyServer, error)

NewProxyServer creates a new proxy server

func (*ProxyServer) Start

func (p *ProxyServer) Start() error

Start starts the proxy server with graceful shutdown support

type RequestData

type RequestData struct {
	Method      string
	Path        string
	QueryParams url.Values
	Headers     http.Header
	Body        []byte
	Timestamp   time.Time
}

RequestData stores information about an HTTP request

type ResponseData

type ResponseData struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
	Timestamp  time.Time
}

ResponseData stores information about an HTTP response

type Storage

type Storage interface {
	Store(transaction APITransaction) error
	GetAll() ([]APITransaction, error)
	Clear() error
}

Storage interface for storing API transactions

Jump to

Keyboard shortcuts

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