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
funcDebugHeaders()
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.
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.
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.
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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-06 UTC."],[[["\u003cp\u003eThis page details the \u003ccode\u003ehttpreplay\u003c/code\u003e package, which offers tools for recording and replaying HTTP traffic from Google API clients.\u003c/p\u003e\n"],["\u003cp\u003eThe package includes \u003ccode\u003eRecorder\u003c/code\u003e for logging interactions and \u003ccode\u003eReplayer\u003c/code\u003e to reproduce those interactions, with the latest version being 0.120.0.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eNewRecorder\u003c/code\u003e creates a recorder to log interactions to a specified file, and \u003ccode\u003eNewReplayer\u003c/code\u003e reads from that file to set up the replaying process.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eRecorder\u003c/code\u003e and \u003ccode\u003eReplayer\u003c/code\u003e types provide \u003ccode\u003eClient\u003c/code\u003e methods to obtain an HTTP client for recording or replaying, respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe package offers functions to modify headers and query parameters during recording and replay, and is designed to function with Go version 1.8 or higher.\u003c/p\u003e\n"]]],[],null,["Version 0.110.10keyboard_arrow_down\n\n- [0.122.0 (latest)](/go/docs/reference/cloud.google.com/go/latest/httpreplay)\n- [0.121.6](/go/docs/reference/cloud.google.com/go/0.121.6/httpreplay)\n- [0.120.1](/go/docs/reference/cloud.google.com/go/0.120.1/httpreplay)\n- [0.119.0](/go/docs/reference/cloud.google.com/go/0.119.0/httpreplay)\n- [0.118.3](/go/docs/reference/cloud.google.com/go/0.118.3/httpreplay)\n- [0.117.0](/go/docs/reference/cloud.google.com/go/0.117.0/httpreplay)\n- [0.116.0](/go/docs/reference/cloud.google.com/go/0.116.0/httpreplay)\n- [0.115.1](/go/docs/reference/cloud.google.com/go/0.115.1/httpreplay)\n- [0.114.0](/go/docs/reference/cloud.google.com/go/0.114.0/httpreplay)\n- [0.113.0](/go/docs/reference/cloud.google.com/go/0.113.0/httpreplay)\n- [0.112.2](/go/docs/reference/cloud.google.com/go/0.112.2/httpreplay)\n- [0.111.0](/go/docs/reference/cloud.google.com/go/0.111.0/httpreplay)\n- [0.110.10](/go/docs/reference/cloud.google.com/go/0.110.10/httpreplay)\n- [0.109.0](/go/docs/reference/cloud.google.com/go/0.109.0/httpreplay)\n- [0.108.0](/go/docs/reference/cloud.google.com/go/0.108.0/httpreplay)\n- [0.107.0](/go/docs/reference/cloud.google.com/go/0.107.0/httpreplay)\n- [0.106.0](/go/docs/reference/cloud.google.com/go/0.106.0/httpreplay)\n- [0.105.0](/go/docs/reference/cloud.google.com/go/0.105.0/httpreplay)\n- [0.104.0](/go/docs/reference/cloud.google.com/go/0.104.0/httpreplay)\n- [0.103.0](/go/docs/reference/cloud.google.com/go/0.103.0/httpreplay)\n- [0.102.1](/go/docs/reference/cloud.google.com/go/0.102.1/httpreplay)\n- [0.101.1](/go/docs/reference/cloud.google.com/go/0.101.1/httpreplay)\n- [0.100.2](/go/docs/reference/cloud.google.com/go/0.100.2/httpreplay)\n- [0.99.0](/go/docs/reference/cloud.google.com/go/0.99.0/httpreplay)\n- [0.98.0](/go/docs/reference/cloud.google.com/go/0.98.0/httpreplay)\n- [0.97.0](/go/docs/reference/cloud.google.com/go/0.97.0/httpreplay)\n- [0.96.0](/go/docs/reference/cloud.google.com/go/0.96.0/httpreplay)\n- [0.95.0](/go/docs/reference/cloud.google.com/go/0.95.0/httpreplay)\n- [0.94.1](/go/docs/reference/cloud.google.com/go/0.94.1/httpreplay)\n- [0.93.3](/go/docs/reference/cloud.google.com/go/0.93.3/httpreplay)\n- [0.92.3](/go/docs/reference/cloud.google.com/go/0.92.3/httpreplay)\n- [0.91.1](/go/docs/reference/cloud.google.com/go/0.91.1/httpreplay)\n- [0.90.0](/go/docs/reference/cloud.google.com/go/0.90.0/httpreplay)\n- [0.89.0](/go/docs/reference/cloud.google.com/go/0.89.0/httpreplay)\n- [0.88.0](/go/docs/reference/cloud.google.com/go/0.88.0/httpreplay)\n- [0.87.0](/go/docs/reference/cloud.google.com/go/0.87.0/httpreplay)\n- [0.86.0](/go/docs/reference/cloud.google.com/go/0.86.0/httpreplay)\n- [0.85.0](/go/docs/reference/cloud.google.com/go/0.85.0/httpreplay)\n- [0.84.0](/go/docs/reference/cloud.google.com/go/0.84.0/httpreplay)\n- [0.83.0](/go/docs/reference/cloud.google.com/go/0.83.0/httpreplay)\n- [0.82.0](/go/docs/reference/cloud.google.com/go/0.82.0/httpreplay)\n- [0.81.0](/go/docs/reference/cloud.google.com/go/0.81.0/httpreplay)\n- [0.80.0](/go/docs/reference/cloud.google.com/go/0.80.0/httpreplay)\n- [0.79.0](/go/docs/reference/cloud.google.com/go/0.79.0/httpreplay)\n- [0.78.0](/go/docs/reference/cloud.google.com/go/0.78.0/httpreplay)\n- [0.77.0](/go/docs/reference/cloud.google.com/go/0.77.0/httpreplay)\n- [0.76.0](/go/docs/reference/cloud.google.com/go/0.76.0/httpreplay)\n- [0.75.0](/go/docs/reference/cloud.google.com/go/0.75.0/httpreplay) \n**Note:** To get more information about this package, such as access to older versions, view [this package on pkg.go.dev](https://pkg.go.dev/cloud.google.com/go/httpreplay). \n\u003cbr /\u003e\n\nPackage httpreplay provides an API for recording and replaying traffic\nfrom HTTP-based Google API clients.\n\nTo record:\n\n1. Call NewRecorder to get a Recorder.\n2. Use its Client method to obtain an HTTP client to use when making API calls.\n3. Close the Recorder when you're done. That will save the log of interactions to the file you provided to NewRecorder.\n\nTo replay:\n\n1. Call NewReplayer with the same filename you used to record to get a Replayer.\n2. Call its Client method and use the client to make the same API calls. You will get back the recorded responses.\n3. Close the Replayer when you're done.\n\nThis package is EXPERIMENTAL and is subject to change or removal without notice.\nIt requires Go version 1.8 or higher. \n\nFunctions\n\nfunc DebugHeaders \n\n func DebugHeaders()\n\nDebugHeaders helps to determine whether a header should be ignored.\nWhen true, if requests have the same method, URL and body but differ\nin a header, the first mismatched header is logged. \n\nfunc Supported \n\n func Supported() https://pkg.go.dev/builtin#bool\n\nSupported reports whether httpreplay is supported in the current version of Go.\nFor Go 1.8 and above, the answer is true. \n\nRecorder \n\n type Recorder struct {\n \t// contains filtered or unexported fields\n }\n\nA Recorder records HTTP interactions. \n\nfunc NewRecorder \n\n func NewRecorder(filename https://pkg.go.dev/builtin#string, initial []https://pkg.go.dev/builtin#byte) (*#cloud_google_com_go_httpreplay_Recorder, https://pkg.go.dev/builtin#error)\n\nNewRecorder creates a recorder that writes to filename. The file will\nalso store initial state that can be retrieved to configure replay.\n\nYou must call Close on the Recorder to ensure that all data is written. \n\nfunc (\\*Recorder) ClearHeaders \n\n func (r *#cloud_google_com_go_httpreplay_Recorder) ClearHeaders(patterns https://pkg.go.dev/builtin#string)\n\nClearHeaders will replace the value of request and response headers that match\nany of the patterns with CLEARED, on both recording and replay.\nUse ClearHeaders when the header information is secret or may change from run to\nrun, but you still want to verify that the headers are being sent and received.\n\nPattern is taken literally except for \\*, which matches any sequence of characters. \n\nfunc (\\*Recorder) ClearQueryParams \n\n func (r *#cloud_google_com_go_httpreplay_Recorder) ClearQueryParams(patterns https://pkg.go.dev/builtin#string)\n\nClearQueryParams will replace the value of URL query parametrs that match any of\nthe patterns with CLEARED, on both recording and replay.\nUse ClearQueryParams when the parameter information is secret or may change from\nrun to run, but you still want to verify that it are being sent.\n\nPattern is taken literally except for \\*, which matches any sequence of characters. \n\nfunc (\\*Recorder) Client \n\n func (r *#cloud_google_com_go_httpreplay_Recorder) Client(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context, opts ...option.ClientOption) (*https://pkg.go.dev/net/http.https://pkg.go.dev/net/http#Client, https://pkg.go.dev/builtin#error)\n\nClient returns an http.Client to be used for recording. Provide authentication options\nlike option.WithTokenSource as you normally would, or omit them to use Application Default\nCredentials. \n\nfunc (\\*Recorder) Close \n\n func (r *#cloud_google_com_go_httpreplay_Recorder) Close() https://pkg.go.dev/builtin#error\n\nClose closes the Recorder and saves the log file. \n\nfunc (\\*Recorder) RemoveQueryParams \n\n func (r *#cloud_google_com_go_httpreplay_Recorder) RemoveQueryParams(patterns https://pkg.go.dev/builtin#string)\n\nRemoveQueryParams will remove URL query parameters matching patterns from the log,\nand skip matching them during replay.\n\nPattern is taken literally except for \\*, which matches any sequence of characters. \n\nfunc (\\*Recorder) RemoveRequestHeaders \n\n func (r *#cloud_google_com_go_httpreplay_Recorder) RemoveRequestHeaders(patterns https://pkg.go.dev/builtin#string)\n\nRemoveRequestHeaders will remove request headers matching patterns from the log,\nand skip matching them during replay.\n\nPattern is taken literally except for \\*, which matches any sequence of characters. \n\nReplayer \n\n type Replayer struct {\n \t// contains filtered or unexported fields\n }\n\nA Replayer replays previously recorded HTTP interactions. \n\nfunc NewReplayer \n\n func NewReplayer(filename https://pkg.go.dev/builtin#string) (*#cloud_google_com_go_httpreplay_Replayer, https://pkg.go.dev/builtin#error)\n\nNewReplayer creates a replayer that reads from filename. \n\nfunc (\\*Replayer) Client \n\n func (r *#cloud_google_com_go_httpreplay_Replayer) Client(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context) (*https://pkg.go.dev/net/http.https://pkg.go.dev/net/http#Client, https://pkg.go.dev/builtin#error)\n\nClient returns an HTTP client for replaying. The client does not need to be\nconfigured with credentials for authenticating to a server, since it never\ncontacts a real backend. \n\nfunc (\\*Replayer) Close \n\n func (r *#cloud_google_com_go_httpreplay_Replayer) Close() https://pkg.go.dev/builtin#error\n\nClose closes the replayer. \n\nfunc (\\*Replayer) IgnoreHeader \n\n func (r *#cloud_google_com_go_httpreplay_Replayer) IgnoreHeader(h https://pkg.go.dev/builtin#string)\n\nIgnoreHeader will not use h when matching requests. \n\nfunc (\\*Replayer) Initial \n\n func (r *#cloud_google_com_go_httpreplay_Replayer) Initial() []https://pkg.go.dev/builtin#byte\n\nInitial returns the initial state saved by the Recorder."]]