func DebugHeaders()
DebugHeaders helps to determine whether a header should be ignored. When true, if requests have the same method, URL and body but differ in a header, the first mismatched header is logged.
func Supported() bool
Supported reports whether httpreplay is supported in the current version of Go. For Go 1.8 and above, the answer is true.
A Recorder records HTTP interactions.
type Recorder struct {
// contains filtered or unexported fields
}
func NewRecorder(filename string, initial []byte) (*Recorder, error)
NewRecorder creates a recorder that writes to filename. The file will also store initial state that can be retrieved to configure replay.
You must call Close on the Recorder to ensure that all data is written.
func (r *Recorder) ClearHeaders(patterns ...string)
ClearHeaders will replace the value of request and response headers that match any of the patterns with CLEARED, on both recording and replay. Use ClearHeaders when the header information is secret or may change from run to run, but you still want to verify that the headers are being sent and received.
Pattern is taken literally except for *, which matches any sequence of characters.
func (r *Recorder) ClearQueryParams(patterns ...string)
ClearQueryParams will replace the value of URL query parametrs that match any of the patterns with CLEARED, on both recording and replay. Use ClearQueryParams when the parameter information is secret or may change from run to run, but you still want to verify that it are being sent.
Pattern is taken literally except for *, which matches any sequence of characters.
func (r *Recorder) Client(ctx context.Context, opts ...option.ClientOption) (*http.Client, error)
Client returns an http.Client to be used for recording. Provide authentication options like option.WithTokenSource as you normally would, or omit them to use Application Default Credentials.
func (r *Recorder) Close() error
Close closes the Recorder and saves the log file.
func (r *Recorder) RemoveQueryParams(patterns ...string)
RemoveQueryParams will remove URL query parameters matching patterns from the log, and skip matching them during replay.
Pattern is taken literally except for *, which matches any sequence of characters.
func (r *Recorder) RemoveRequestHeaders(patterns ...string)
RemoveRequestHeaders will remove request headers matching patterns from the log, and skip matching them during replay.
Pattern is taken literally except for *, which matches any sequence of characters.
A Replayer replays previously recorded HTTP interactions.
type Replayer struct {
// contains filtered or unexported fields
}
func NewReplayer(filename string) (*Replayer, error)
NewReplayer creates a replayer that reads from filename.
func (r *Replayer) Client(ctx context.Context) (*http.Client, error)
Client returns an HTTP client for replaying. The client does not need to be configured with credentials for authenticating to a server, since it never contacts a real backend.
func (r *Replayer) Close() error
Close closes the replayer.
func (r *Replayer) IgnoreHeader(h string)
IgnoreHeader will not use h when matching requests.
func (r *Replayer) Initial() []byte
Initial returns the initial state saved by the Recorder.