Skip to content

Commit c7473c2

Browse files
committed
EOF error fix
1 parent 7d5fe5b commit c7473c2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

api/util/logger.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package util
22

33
import (
4+
"bytes"
45
"github.com/devtron-labs/devtron/internal/middleware"
56
"github.com/devtron-labs/devtron/pkg/user"
67
"io"
@@ -42,16 +43,23 @@ func (impl LoggingMiddlewareImpl) LoggingMiddleware(next http.Handler) http.Hand
4243
if err != nil {
4344
log.Printf("AUDIT_LOG: user does not exists")
4445
}
45-
body, err := io.ReadAll(r.Body)
46+
47+
// Read the request body into a buffer
48+
var bodyBuffer bytes.Buffer
49+
_, err = io.Copy(&bodyBuffer, r.Body)
4650
if err != nil {
4751
log.Printf("AUDIT_LOG: error reading request body for urlPath: %s queryParams: %s userEmail: %s", r.URL.Path, r.URL.Query().Encode(), userEmail)
4852
}
53+
54+
// Restore the request body for downstream handlers
55+
r.Body = io.NopCloser(&bodyBuffer)
56+
4957
auditLogDto := &AuditLoggerDTO{
5058
UrlPath: r.URL.Path,
5159
UserEmail: userEmail,
5260
UpdatedOn: time.Now(),
5361
QueryParams: r.URL.Query().Encode(),
54-
RequestPayload: body,
62+
RequestPayload: bodyBuffer.Bytes(),
5563
}
5664
// Call the next handler in the chain.
5765
next.ServeHTTP(d, r)

0 commit comments

Comments
 (0)