Skip to content

Instantly share code, notes, and snippets.

@termie
Created June 23, 2016 21:29
Show Gist options
  • Save termie/4ef1901c070f2c6d36d5c075dbde9a49 to your computer and use it in GitHub Desktop.
Save termie/4ef1901c070f2c6d36d5c075dbde9a49 to your computer and use it in GitHub Desktop.
debug http requests for oauth
type DebugRoundTripper struct {
transport http.RoundTripper
out io.Writer
}
func (d *DebugRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
outreq, _ := httputil.DumpRequestOut(req, false)
fmt.Fprintf(os.Stderr, "REQOUT:\n%q\n", outreq)
resp, err := d.transport.RoundTrip(req)
if resp != nil {
outresp, _ := httputil.DumpResponse(resp, false)
fmt.Fprintf(os.Stderr, "RESP:\n%q\n", outresp)
}
return resp, err
}
func main() {
// For appengine
client := &http.Client{Transport: &DebugRoundTripper{&urlfetch.Transport{ctx, false}, os.Stderr}}
// For non-appengine
client := &http.Client{Transport: &DebugRoundTripper{http.DefaultTransport, os.Stderr}}
ctx = context.WithValue(ctx, oauth2.HTTPClient, client)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment