Documentation ¶
Index ¶
- Constants
- Variables
- func BodyTemplate() *template.Template
- func DeserializeRequest(s *SerializableRequest) (*http.Request, error)
- func DeserializeResponse(s *SerializableResponse, templateVars map[string]any) (*http.Response, error)
- func EnsureUserConfigDir() (string, error)
- func NewSnapshotMiddleware(topic SnapshotMessageTopic, getCurrentTime timeFunc) func(handler http.Handler) http.Handler
- func UserConfigDir() string
- type CertPool
- type HTTPMessage
- type MatchRule
- type MultiReadRequestCloner
- type MultiReadResponseCloner
- type RequestCloner
- type RequestRecorder
- type RequestTemplateVars
- func (r *RequestTemplateVars) Body() string
- func (r *RequestTemplateVars) Form(key string) string
- func (r *RequestTemplateVars) Header(key string) string
- func (r *RequestTemplateVars) JSON(path string) any
- func (r *RequestTemplateVars) Query(key string) string
- func (r *RequestTemplateVars) URL() *url.URL
- type ResponseCloner
- type ResponseRecorder
- type RuleGroup
- type SerializableRequest
- type SerializableResponse
- type Snapshot
- type SnapshotMatchFunc
- type SnapshotMessageTopic
- type SnapshotRecorder
- type SnapshotRef
- type SnapshotRouter
- type SnapshotStore
Constants ¶
const ( ToolName = "wiretap" CAName = "Wiretap CA" )
Variables ¶
Functions ¶
func BodyTemplate ¶
func DeserializeRequest ¶
func DeserializeRequest(s *SerializableRequest) (*http.Request, error)
func DeserializeResponse ¶
func EnsureUserConfigDir ¶
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 HTTPMessage ¶
type MultiReadRequestCloner ¶
func (MultiReadRequestCloner) Body ¶
func (r MultiReadRequestCloner) Body() []byte
func (MultiReadRequestCloner) Clone ¶
func (r MultiReadRequestCloner) Clone() *http.Request
type MultiReadResponseCloner ¶
func (MultiReadResponseCloner) Body ¶
func (r MultiReadResponseCloner) Body() []byte
func (MultiReadResponseCloner) Clone ¶
func (r MultiReadResponseCloner) Clone() *http.Response
type RequestCloner ¶
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 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) 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 ¶
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 NewSnapshotRecorder ¶
func NewSnapshotRecorder( w http.ResponseWriter, r *http.Request, topic SnapshotMessageTopic, start time.Time, ) (*SnapshotRecorder, http.ResponseWriter, *http.Request)
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) }