diff options
author | 2024-04-30 15:15:50 +0100 | |
---|---|---|
committer | 2024-04-30 16:15:50 +0200 | |
commit | ec334ece207325aefb91a7840c741d9ee4f9a8b9 (patch) | |
tree | 692bf509d8bced1b5b7561f8c8275d05bf9a921b /internal/httpclient/request.go | |
parent | [docs] Remove last references to RPi (#2885) (diff) | |
download | gotosocial-ec334ece207325aefb91a7840c741d9ee4f9a8b9.tar.xz |
[chore] include attemptno in httpclient logs (#2887)
* include request attempt number in httpclient logs
* slightly nicer attempt number formatting
Diffstat (limited to 'internal/httpclient/request.go')
-rw-r--r-- | internal/httpclient/request.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/internal/httpclient/request.go b/internal/httpclient/request.go index 0df9211e7..e5a7f44d3 100644 --- a/internal/httpclient/request.go +++ b/internal/httpclient/request.go @@ -50,10 +50,16 @@ type Request struct { func WrapRequest(r *http.Request) Request { var rr Request rr.Request = r - rr.Entry = log.WithContext(r.Context()). - WithField("method", r.Method). - WithField("url", r.URL.String()). - WithField("contentType", r.Header.Get("Content-Type")) + entry := log.WithContext(r.Context()) + entry = entry.WithField("method", r.Method) + entry = entry.WithField("url", r.URL.String()) + if r.Body != nil { + // Only add content-type header if a request body exists. + entry = entry.WithField("contentType", r.Header.Get("Content-Type")) + } + // note our formatting library follows ptr values + entry = entry.WithField("attempt", &rr.attempts) + rr.Entry = entry return rr } |