You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.9 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # httpr, a Record/Replay Proxy
  2. httpr is an HTTP proxy that records and replays traffic. It is designed
  3. specifically for Google APIs that use HTTP exclusively. These include the Google
  4. Cloud Storage and BigQuery clients, as well as the clients in the
  5. `github.com/google/google-api-*-client` repos.
  6. If you are writing Go code, you should use the `cloud.google.com/go/httpreplay` package, which
  7. is a simpler way to use the proxy.
  8. ## Using a Record/Replay Proxy
  9. A record/replay proxy lets you run an "integration" test that accesses a
  10. backend like a Google service and record the interaction. Subsequent runs of the
  11. test can replay the server's responses without actually contacting the server,
  12. turning the integration test into a fast and inexpensive unit test.
  13. ## Usage
  14. First, obtain the `httpr` binary. If you have the Go toolchain, you can run `go
  15. get -u cloud.google.com/go/httpreplay/cmd/httpr`. Otherwise, precompiled
  16. binaries for various architectures and operating systems are available from [the
  17. releases page](https://github.com/googleapis/google-cloud-go/releases).
  18. ### Recording
  19. 1. Start `httpr` in record mode by passing it the `-record` flag with a filename:
  20. ```
  21. httpr -record myclient.replay
  22. ```
  23. By default, `httpr` will run on port 8080, and open a control port on 8181.
  24. You can change these with the `-port` and `-control-port` flags.
  25. You will want to run `httpr` in the background or in another window.
  26. 1. In order for `httpr` to record HTTPS traffic, your client must trust it. It
  27. does so by installing a CA certificate created by `httpr` during the
  28. recording session. To obtain the certificate in PEM form, GET the URL
  29. `http://localhost:8181/authority.cer`. (If you changed the control port, use
  30. it in place of 8181.) Consult your language to determine
  31. how to install the certificate. Note that the certificate is different for each run
  32. of `httpr`.
  33. 1. Arrange for your test program to use `httpr` as a proxy. This may be as
  34. simple as setting the `HTTPS_PROXY` environment variable.
  35. 1. Run your test program, using whatever authentication for your Google API
  36. clients that you wish.
  37. 1. Send `httpr` a SIGINT signal (`kill -2`). `httpr` will write
  38. the replay file, then exit.
  39. ### Replaying
  40. 1. Start `httpr` in replay mode, in the background or another window:
  41. ```
  42. httpr -replay myclient.replay
  43. ```
  44. 1. Install the CA certificate as described above.
  45. 1. Have your test program treat `httpr` as a proxy, as described above.
  46. 1. Run your test program. Your Google API clients should use no authentication.
  47. ## Tips
  48. You must remove all randomness from your interaction while recording,
  49. so that the replay is fully deterministic.
  50. Note that BigQuery clients choose random values for job IDs and insert ID if you
  51. do not supply them. Either supply your own, or seed the client's random number
  52. generator if possible.
  53. ## Examples
  54. Examples of running `httpr` can be found in `examples` under this file's directory.