MCPcopy Create free account
hub / github.com/exercism/cli / DumpRequest

Function DumpRequest

debug/debug.go:37–66  ·  view source on GitHub ↗

DumpRequest dumps out the provided http.Request

(req *http.Request)

Source from the content-addressed store, hash-verified

35
36// DumpRequest dumps out the provided http.Request
37func DumpRequest(req *http.Request) {
38 if !Verbose {
39 return
40 }
41
42 var bodyCopy bytes.Buffer
43 body := io.TeeReader(req.Body, &bodyCopy)
44 req.Body = io.NopCloser(body)
45
46 authHeader := req.Header.Get("Authorization")
47
48 if authParts := strings.Split(authHeader, " "); len(authParts) > 1 && !UnmaskAPIKey {
49 if token := authParts[1]; token != "" {
50 req.Header.Set("Authorization", "Bearer "+Redact(token))
51 }
52 }
53
54 dump, err := httputil.DumpRequest(req, req.ContentLength > 0)
55 if err != nil {
56 log.Fatal(err)
57 }
58
59 Println("\n========================= BEGIN DumpRequest =========================")
60 Println(string(dump))
61 Println("========================= END DumpRequest =========================")
62 Println("")
63
64 req.Header.Set("Authorization", authHeader)
65 req.Body = io.NopCloser(&bodyCopy)
66}
67
68// DumpResponse dumps out the provided http.Response
69func DumpResponse(res *http.Response) {

Callers 2

DoMethod · 0.92
TestDumpRequestFunction · 0.85

Calls 2

RedactFunction · 0.85
PrintlnFunction · 0.85

Tested by 1

TestDumpRequestFunction · 0.68