Skip to content
Snippets Groups Projects
Commit e04829b3 authored by Francé Wilke's avatar Francé Wilke
Browse files

Always truncate the response body

parent d791b796
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,6 @@ package api_logs
import (
"github.com/thoas/go-funk"
"gitlab.com/uafrica/go-utils/string_utils"
"net/http"
"net/url"
"strings"
"time"
......@@ -19,14 +18,11 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st
currentRequestID = *requestID
}
// Truncate response body for incoming GET requests
responseBody := res.Body
if req.HTTPMethod == http.MethodGet {
// SQS has a 256KB limit, so let's limit the response to 96KB
responseBody := res.Body
if len(responseBody) > 12000 {
responseBody = responseBody[:12000] + "..."
}
}
var authType string
var authUsername string
......@@ -117,6 +113,12 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st
currentRequestID = *requestID
}
// SQS has a 256KB limit, so let's limit the response to 96KB
originalResponseBody := responseBody
if len(responseBody) > 12000 {
responseBody = responseBody[:12000] + "..."
}
userID, _ := claim["UserID"].(int64)
username, _ := claim["Username"].(string)
accountID, _ := claim["AccountID"].(int64)
......@@ -157,7 +159,7 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st
},
Response: ApiLogResponse{
Headers: requestHeaders,
BodySize: len(responseBody),
BodySize: len(originalResponseBody),
Body: responseBody,
},
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment