fix http debugger

This commit is contained in:
2026-05-29 11:27:40 +02:00
parent f7302ea506
commit 57bbe680a7

View File

@@ -246,22 +246,29 @@ type DebugTransport struct {
} }
func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) { func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
buf := new(bytes.Buffer) content := ""
contentline := ""
body, _ := req.GetBody() if req.ContentLength > 0 {
buf := new(bytes.Buffer)
body, _ := req.GetBody()
_, err := buf.ReadFrom(body) _, err := buf.ReadFrom(body)
if err != nil { if err != nil {
return nil, err return nil, err
}
var pretty bytes.Buffer
err = json.Indent(&pretty, buf.Bytes(), "", "\t")
if err != nil {
return nil, fmt.Errorf("json parse error: %s", err)
}
content = pretty.String()
contentline = buf.String()
} }
var pretty bytes.Buffer slog.Info("req", "host", req.URL.Host, "uri", req.URL.Path, "body", content, "bodyline", contentline)
err = json.Indent(&pretty, buf.Bytes(), "", "\t")
if err != nil {
return nil, fmt.Errorf("json parse error: %s", err)
}
slog.Info("req", "host", req.URL.Host, "uri", req.URL.Path, "body", pretty.String(), "bodyline", buf.String())
return t.Transport.RoundTrip(req) return t.Transport.RoundTrip(req)
} }