- 0.117.0 (latest)
- 0.116.0
- 0.115.1
- 0.114.0
- 0.113.0
- 0.112.2
- 0.111.0
- 0.110.10
- 0.109.0
- 0.108.0
- 0.107.0
- 0.106.0
- 0.105.0
- 0.104.0
- 0.103.0
- 0.102.1
- 0.101.1
- 0.100.2
- 0.99.0
- 0.98.0
- 0.97.0
- 0.96.0
- 0.95.0
- 0.94.1
- 0.93.3
- 0.92.3
- 0.91.1
- 0.90.0
- 0.89.0
- 0.88.0
- 0.87.0
- 0.86.0
- 0.85.0
- 0.84.0
- 0.83.0
- 0.82.0
- 0.81.0
- 0.80.0
- 0.79.0
- 0.78.0
- 0.77.0
- 0.76.0
- 0.75.0
Package httpreplay provides an API for recording and replaying traffic from 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 interactions to 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.
Functions
func DebugHeaders
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
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.
Recorder
type Recorder struct {
// contains filtered or unexported fields
}
A Recorder records HTTP interactions.
func NewRecorder
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 (*Recorder) ClearHeaders
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 (*Recorder) ClearQueryParams
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 (*Recorder) Client
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 (*Recorder) Close
Close closes the Recorder and saves the log file.
func (*Recorder) RemoveQueryParams
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
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.
Replayer
type Replayer struct {
// contains filtered or unexported fields
}
A Replayer replays previously recorded HTTP interactions.
func NewReplayer
NewReplayer creates a replayer that reads from filename.
func (*Replayer) Client
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 (*Replayer) Close
Close closes the replayer.
func (*Replayer) IgnoreHeader
IgnoreHeader will not use h when matching requests.
func (*Replayer) Initial
Initial returns the initial state saved by the Recorder.