Last active
August 13, 2020 19:15
-
-
Save rafaelsq/b790c91a9e422e60c036e3cdd06c4d97 to your computer and use it in GitHub Desktop.
Print Request
This file contains 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
package main | |
import ( | |
"io" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"os" | |
) | |
type DumpTransport struct { | |
r http.RoundTripper | |
} | |
func (d *DumpTransport) RoundTrip(h *http.Request) (*http.Response, error) { | |
dump, _ := httputil.DumpRequestOut(h, true) | |
os.Stdout.WriteString("\nREQUEST===========================\n") | |
os.Stdout.Write(dump) | |
os.Stdout.WriteString(".end--------------------------------\n") | |
resp, err := d.r.RoundTrip(h) | |
dump, _ = httputil.DumpResponse(resp, true) | |
os.Stdout.WriteString("\nRESPONSE==========================\n") | |
os.Stdout.Write(dump) | |
os.Stdout.WriteString(".end--------------------------------\n") | |
return resp, err | |
} | |
func main() { | |
client := http.Client{ | |
Transport: &DumpTransport{http.DefaultTransport}, | |
} | |
resp, err := client.Get("https://gist.github.com/rafaelsq/b790c91a9e422e60c036e3cdd06c4d97") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer resp.Body.Close() | |
io.Copy(ioutil.Discard, resp.Body) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment