Flag for dumping HTTPS traffic? #552

kevinburke opened this Issue Feb 16, 2017 · 5 comments


None yet

3 participants

kevinburke commented Feb 16, 2017 edited

I find it pretty useful to be able to inspect the raw HTTP request/response being issued by a client library. This makes it easy to add integration tests to my own code, by copying the JSON responses from Github into my tests, then setting up a httptest.Server to replay those responses.

Here's how I implement this in my own API client - you can set DEBUG_HTTP_TRAFFIC=true in the environment to dump all requests/responses. https://github.com/kevinburke/rest/blob/master/client.go#L110-L134

And here's where I am using a response captured by that logic, in a test: https://github.com/saintpete/logrole/blob/master/server/messages_test.go#L88

Thoughts on adding something similar to this library?

shurcooL commented Feb 16, 2017 edited

Can this be done via a middleware http.RoundTripper implementation? If so, it can be orthogonal to this specific library.

Something like:

type dumper struct{
    T http.RoundTripper

func (d dumper) RoundTrip(req *http.Request) (*http.Response, error) {
    // dump req ...
    resp, err := d.T.RoundTrip(req)
    // dump resp ...
    return resp, err

transport := dumper{T: http.DefaultTransport}
github.NewClient(http.Client{Transport: transport})

We have exactly such a roundtripper internally at Google.


@willnorris bah haha, I just added kevinburke/rest@da85e32 as a public implementation!


Is there anything left here, or can we close this?


nope you can close it

@shurcooL shurcooL closed this Feb 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment