From fd687a409b3333cd4c88a1612a90dc098833b45c Mon Sep 17 00:00:00 2001 From: "Lixia (Sylvia) Lei" Date: Sat, 30 Nov 2024 23:58:41 +0800 Subject: [PATCH] minor Signed-off-by: Lixia (Sylvia) Lei --- internal/trace/transport.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/trace/transport.go b/internal/trace/transport.go index ffd139277..66ba36111 100644 --- a/internal/trace/transport.go +++ b/internal/trace/transport.go @@ -100,18 +100,17 @@ func logHeader(header http.Header) string { // TODO: test and docs func logResponseBody(resp *http.Response) string { if resp.Body == nil || resp.ContentLength <= 0 || resp.Body == http.NoBody { - return " Empty body" + return "" } contentType := resp.Header.Get("Content-Type") if !shouldPrint(contentType) { - return " Body of this content type is not printed" + return fmt.Sprintf(" Body of content type \"%s\" is not printed", contentType) } if resp.ContentLength > payloadSizeLimit { - return fmt.Sprintf(" Body larger to %d bytes is not printed", payloadSizeLimit) + return fmt.Sprintf(" Body larger than %d bytes is not printed", payloadSizeLimit) } var builder strings.Builder - // TODO: what if body has been read out? tr := io.TeeReader(resp.Body, &builder) bodyBytes, err := io.ReadAll(tr) if err != nil { @@ -123,9 +122,11 @@ func logResponseBody(resp *http.Response) string { } func shouldPrint(contentType string) bool { + // JSON types if strings.HasPrefix(contentType, "application/json") || strings.HasSuffix(contentType, "+json") { return true } + // text types if strings.HasPrefix(contentType, "text/") { return true }