spec

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolName = "wiretap"
	CAName   = "Wiretap CA"
)

Variables

View Source
var (
	ErrFileNotFoundInTxtArchive = errors.New("file not found in txt archive")
	ErrReadRoundTripTimeout     = errors.New("timed out waiting for round trip record")
	ErrSnapshotIDRequired       = errors.New("snapshot ID is required")
)

Functions

func BodyTemplate

func BodyTemplate() *template.Template

func DeserializeRequest

func DeserializeRequest(s *SerializableRequest) (*http.Request, error)

func DeserializeResponse

func DeserializeResponse(s *SerializableResponse, templateVars map[string]any) (*http.Response, error)

func EnsureUserConfigDir

func EnsureUserConfigDir() (string, error)

func NewSnapshotMiddleware

func NewSnapshotMiddleware(topic SnapshotMessageTopic, getCurrentTime timeFunc) func(handler http.Handler) http.Handler

NewSnapshotMiddleware returns a middleware that will capture snapshots of requests and responses and publish them to the provided topic. The middleware will also inject a timeFunc into the request context that will return the time the request was received. This is useful for testing and making the time deterministic. NOTE: This middleware will delete the Accept-Encoding header from the request This is because go's transport library will not decompress the response body if an upstream client requested compression.

func UserConfigDir

func UserConfigDir() string

Types

type CertPool

type CertPool interface {
	ToTLSConfig() *tls.Config
}

type HTTPMessage

type HTTPMessage struct {
	Header           http.Header
	Body             string
	ContentType      string
	ContentLength    int64
	TransferEncoding []string
	Raw              string
}

type MatchRule

type MatchRule interface {
	Match(req *http.Request) (match bool, err error)
}

type MultiReadRequestCloner

type MultiReadRequestCloner struct {
	Req *http.Request
}

func (MultiReadRequestCloner) Body

func (r MultiReadRequestCloner) Body() []byte

func (MultiReadRequestCloner) Clone

func (r MultiReadRequestCloner) Clone() *http.Request

type MultiReadResponseCloner

type MultiReadResponseCloner struct {
	Res *http.Response
}

func (MultiReadResponseCloner) Body

func (r MultiReadResponseCloner) Body() []byte

func (MultiReadResponseCloner) Clone

type RequestCloner

type RequestCloner interface {
	Body() []byte
	Clone() *http.Request
}

type RequestRecorder

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

func NewRequestRecorder

func NewRequestRecorder(r *http.Request) *RequestRecorder

func (RequestRecorder) Body

func (r RequestRecorder) Body() []byte

func (RequestRecorder) Clone

func (r RequestRecorder) Clone() *http.Request

type RequestTemplateVars

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

func RequestToTemplate

func RequestToTemplate(req *http.Request) (*RequestTemplateVars, error)

func (*RequestTemplateVars) Body

func (r *RequestTemplateVars) Body() string

func (*RequestTemplateVars) Form

func (r *RequestTemplateVars) Form(key string) string

func (*RequestTemplateVars) Header

func (r *RequestTemplateVars) Header(key string) string

func (*RequestTemplateVars) JSON

func (r *RequestTemplateVars) JSON(path string) any

func (*RequestTemplateVars) Query

func (r *RequestTemplateVars) Query(key string) string

func (*RequestTemplateVars) URL

func (r *RequestTemplateVars) URL() *url.URL

type ResponseCloner

type ResponseCloner interface {
	Body() []byte
	Clone() *http.Response
}

type ResponseRecorder

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

func NewResponseRecorder

func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder

func (*ResponseRecorder) Body

func (r *ResponseRecorder) Body() []byte

func (*ResponseRecorder) Clone

func (r *ResponseRecorder) Clone() *http.Response

func (*ResponseRecorder) Header

func (r *ResponseRecorder) Header() http.Header

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(b []byte) (int, error)

func (*ResponseRecorder) WriteHeader

func (r *ResponseRecorder) WriteHeader(statusCode int)

type RuleGroup

type RuleGroup struct {
	Ref        *SnapshotRef
	MatchRules []MatchRule
}

type SerializableRequest

type SerializableRequest struct {
	HTTPMessage
	Method string
	URL    *url.URL
}

func SerializeRequest

func SerializeRequest(r RequestCloner) (*SerializableRequest, error)

type SerializableResponse

type SerializableResponse struct {
	HTTPMessage
	StatusCode int
	Status     string
}

func SerializeResponse

func SerializeResponse(rc ResponseCloner) (*SerializableResponse, error)

type Snapshot

type Snapshot struct {
	ID       string
	Secure   bool
	Duration time.Duration
	Request  *SerializableRequest
	Response *SerializableResponse
}

Snapshot a heavy object that contains a reconstructed http request and response pair

func NewSnapshot

func NewSnapshot(req RequestCloner, res ResponseCloner, elapsed time.Duration) (*Snapshot, error)

func (Snapshot) Ref

func (s Snapshot) Ref() *SnapshotRef

Ref generates a lightweight reference to a snapshot

type SnapshotMatchFunc

type SnapshotMatchFunc func(req *http.Request, groups []RuleGroup) (ref *SnapshotRef, err error)

type SnapshotMessageTopic

type SnapshotMessageTopic messaging.Topic[Snapshot]

func NewSnapshotMessageTopic

func NewSnapshotMessageTopic() SnapshotMessageTopic

type SnapshotRecorder

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

SnapshotRecorder is a recorder that will capture snapshots of requests and responses This is intended for use in http.Handler middleware. The caller must call Done() on the recorder when the request is complete. It is recommended to call Capture() in a goroutine to avoid blocking the request on publishing the snapshot. It is also recommended that you defer Done() to ensure it is called even if the request panics.

func (SnapshotRecorder) Capture

func (r SnapshotRecorder) Capture(now func() time.Time)

func (SnapshotRecorder) Done

func (r SnapshotRecorder) Done()

func (SnapshotRecorder) Duration

func (r SnapshotRecorder) Duration() time.Duration

type SnapshotRef

type SnapshotRef struct {
	ID string `json:"id"`
}

SnapshotRef a lightweight reference to a snapshot

func NewSnapshotRef

func NewSnapshotRef(s string) *SnapshotRef

type SnapshotRouter

type SnapshotRouter interface {
	Match(req *http.Request) (ref *SnapshotRef, er error)
	Register(ref *SnapshotRef, rules ...MatchRule) SnapshotRouter
}

type SnapshotStore

type SnapshotStore interface {
	Read(ref *SnapshotRef) (snapshot *Snapshot, err error)
	Write(snapshot *Snapshot) (ref *SnapshotRef, err error)
}

Jump to

Keyboard shortcuts

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