Created
June 23, 2016 21:29
-
-
Save termie/4ef1901c070f2c6d36d5c075dbde9a49 to your computer and use it in GitHub Desktop.
debug http requests for oauth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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