httpr is an HTTP proxy that records and replays traffic. It is designed specifically for Google APIs that use HTTP exclusively. These include the Google Cloud Storage and BigQuery clients, as well as the clients in the
If you are writing Go code, you should use the
cloud.google.com/go/httpreplay package, which is a simpler way to use the proxy.
A record/replay proxy lets you run an “integration” test that accesses a backend like a Google service and record the interaction. Subsequent runs of the test can replay the server's responses without actually contacting the server, turning the integration test into a fast and inexpensive unit test.
First, obtain the
httpr binary. If you have the Go toolchain, you can run
go get -u cloud.google.com/go/httpreplay/cmd/httpr. Otherwise, precompiled binaries for various architectures and operating systems are available from the releases page.
httprin record mode by passing it the
-recordflag with a filename:
httpr -record myclient.replayBy default,
httprwill run on port 8080, and open a control port on 8181. You can change these with the
-control-portflags. You will want to run
httprin the background or in another window.
httprto record HTTPS traffic, your client must trust it. It does so by installing a CA certificate created by
httprduring the recording session. To obtain the certificate in PEM form, GET the URL
http://localhost:8181/authority.cer. (If you changed the control port, use it in place of 8181.) Consult your language to determine how to install the certificate. Note that the certificate is different for each run of
httpras a proxy. This may be as simple as setting the
httpra SIGINT signal (
httprwill write the replay file, then exit.
httprin replay mode, in the background or another window:
httpr -replay myclient.replay
httpras a proxy, as described above.
You must remove all randomness from your interaction while recording, so that the replay is fully deterministic.
Note that BigQuery clients choose random values for job IDs and insert ID if you do not supply them. Either supply your own, or seed the client's random number generator if possible.
Examples of running
httpr can be found in
examples under this file's directory.