httpreplay
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package httpreplay provides an API for recording and replaying trafficfrom HTTP-based Google API clients.
To record:
- Call NewRecorder to get a Recorder.
- Use its Client method to obtain an HTTP client to use when making API calls.
- Close the Recorder when you're done. That will save the log of interactionsto the file you provided to NewRecorder.
To replay:
- Call NewReplayer with the same filename you used to record to get a Replayer.
- Call its Client method and use the client to make the same API calls.You will get back the recorded responses.
- Close the Replayer when you're done.
This package is EXPERIMENTAL and is subject to change or removal without notice.It requires Go version 1.8 or higher.
Index¶
- func DebugHeaders()
- func Supported() bool
- type Recorder
- func (r *Recorder) ClearHeaders(patterns ...string)
- func (r *Recorder) ClearQueryParams(patterns ...string)
- func (r *Recorder) Client(ctx context.Context, opts ...option.ClientOption) (*http.Client, error)
- func (r *Recorder) Close() error
- func (r *Recorder) RemoveQueryParams(patterns ...string)
- func (r *Recorder) RemoveRequestHeaders(patterns ...string)
- type Replayer
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcDebugHeaders¶added inv0.23.0
func DebugHeaders()
DebugHeaders helps to determine whether a header should be ignored.When true, if requests have the same method, URL and body but differin a header, the first mismatched header is logged.
Types¶
typeRecorder¶
type Recorder struct {// contains filtered or unexported fields}A Recorder records HTTP interactions.
funcNewRecorder¶
NewRecorder creates a recorder that writes to filename. The file willalso 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 (*Recorder)ClearHeaders¶added inv0.35.0
ClearHeaders will replace the value of request and response headers that matchany of the patterns with CLEARED, on both recording and replay.Use ClearHeaders when the header information is secret or may change from run torun, 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 (*Recorder)ClearQueryParams¶added inv0.35.0
ClearQueryParams will replace the value of URL query parametrs that match any ofthe patterns with CLEARED, on both recording and replay.Use ClearQueryParams when the parameter information is secret or may change fromrun 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 (*Recorder)Client¶
Client returns an http.Client to be used for recording. Provide authentication optionslike option.WithTokenSource as you normally would, or omit them to use Application DefaultCredentials.
func (*Recorder)RemoveQueryParams¶added inv0.35.0
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 (*Recorder)RemoveRequestHeaders¶added inv0.35.0
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.
typeReplayer¶
type Replayer struct {// contains filtered or unexported fields}A Replayer replays previously recorded HTTP interactions.
funcNewReplayer¶
NewReplayer creates a replayer that reads from filename.
func (*Replayer)Client¶
Client returns an HTTP client for replaying. The client does not need to beconfigured with credentials for authenticating to a server, since it nevercontacts a real backend.
func (*Replayer)IgnoreHeader¶added inv0.25.0
IgnoreHeader will not use h when matching requests.