MCPcopy
hub / github.com/qustavo/httplab / writeBody

Function writeBody

dump.go:32–50  ·  view source on GitHub ↗
(buf *bytes.Buffer, req *http.Request)

Source from the content-addressed store, hash-verified

30}
31
32func writeBody(buf *bytes.Buffer, req *http.Request) error {
33 body, err := ioutil.ReadAll(req.Body)
34 if err != nil {
35 return err
36 }
37
38 if len(body) > 0 {
39 buf.WriteRune('\n')
40 }
41
42 if strings.Contains(req.Header.Get("Content-Type"), "application/json") {
43 if err := json.Indent(buf, body, "", " "); err == nil {
44 return nil
45 }
46 }
47
48 _, err = buf.Write(body)
49 return err
50}
51
52// DumpRequest pretty prints an http.Request
53func DumpRequest(req *http.Request) ([]byte, error) {

Callers 1

DumpRequestFunction · 0.85

Calls 2

WriteMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected