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

Truncate response body for incoming GET requests

parent 41f20fa5
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ package api_logs ...@@ -3,6 +3,7 @@ package api_logs
import ( import (
"github.com/thoas/go-funk" "github.com/thoas/go-funk"
"gitlab.com/uafrica/go-utils/string_utils" "gitlab.com/uafrica/go-utils/string_utils"
"net/http"
"net/url" "net/url"
"strings" "strings"
"time" "time"
...@@ -18,6 +19,15 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st ...@@ -18,6 +19,15 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st
currentRequestID = *requestID 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
if len(responseBody) > 12000 {
responseBody = responseBody[:12000] + "..."
}
}
var authType string var authType string
var authUsername string var authUsername string
if req.RequestContext.Identity.CognitoAuthenticationType != "" { if req.RequestContext.Identity.CognitoAuthenticationType != "" {
...@@ -87,7 +97,7 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st ...@@ -87,7 +97,7 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st
Response: ApiLogResponse{ Response: ApiLogResponse{
Headers: res.Headers, Headers: res.Headers,
BodySize: len(res.Body), BodySize: len(res.Body),
Body: res.Body, Body: responseBody,
}, },
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment