Esempio n. 1
0
func (c *client) logResponse(res *http.Response) {

	if !c.logResponses {
		return
	}

	w := log.StandardLogger().Writer()

	fmt.Fprintln(w)
	fmt.Fprint(w, "    -------------------------- ")
	fmt.Fprint(w, "HTTP RESPONSE (CLIENT)")
	fmt.Fprintln(w, " -------------------------")

	buf, err := httputil.DumpResponse(
		res,
		res.Header.Get("Content-Type") != "application/octet-stream")
	if err != nil {
		return
	}

	bw := &bytes.Buffer{}
	gotil.WriteIndented(bw, buf)

	scanner := bufio.NewScanner(bw)
	for {
		if !scanner.Scan() {
			break
		}
		fmt.Fprintln(w, scanner.Text())
	}
}
Esempio n. 2
0
func logResponse(
	w io.Writer,
	rec *httptest.ResponseRecorder,
	req *http.Request) {

	fmt.Fprint(w, "    -------------------------- ")
	fmt.Fprint(w, "HTTP RESPONSE (SERVER)")
	fmt.Fprintln(w, " -------------------------")

	for k, v := range rec.HeaderMap {
		fmt.Fprintf(w, "    %s=%s\n", k, strings.Join(v, ","))
	}
	fmt.Fprintln(w, "")
	if !isBinaryContent(rec.HeaderMap) {
		gotil.WriteIndented(w, rec.Body.Bytes())
	}
}
Esempio n. 3
0
func logRequest(
	l bool,
	w io.Writer,
	rec *httptest.ResponseRecorder,
	req *http.Request,
	reqDump []byte) {

	cll := buildCommonLogLine(
		req, *req.URL, time.Now(), rec.Code, rec.Body.Len())
	fmt.Fprintln(w, string(cll))

	if !l || len(reqDump) == 0 {
		return
	}

	fmt.Fprintln(w, "")
	fmt.Fprint(w, "    -------------------------- ")
	fmt.Fprint(w, "HTTP REQUEST (SERVER)")
	fmt.Fprintln(w, " --------------------------")
	gotil.WriteIndented(w, reqDump)
}
Esempio n. 4
0
func (c *client) logRequest(req *http.Request) {

	if !c.logRequests {
		return
	}

	w := log.StandardLogger().Writer()

	fmt.Fprintln(w, "")
	fmt.Fprint(w, "    -------------------------- ")
	fmt.Fprint(w, "HTTP REQUEST (CLIENT)")
	fmt.Fprintln(w, " -------------------------")

	buf, err := httputil.DumpRequest(req, true)
	if err != nil {
		return
	}

	gotil.WriteIndented(w, buf)
	fmt.Fprintln(w)
}