@@ -93,42 +93,38 @@ module.exports = (config = {}, global = window) => {
9393 const redactedUrl = redactQueryParameters ( url , redactedKeys )
9494 const redactedQueryParams = parseQueryParams ( redactedUrl )
9595
96- // Extract request headers
97- const requestHeaders = startContext . headers || { }
98-
99- // Extract request body
100- let requestBody = ''
101- let requestBodyLength = 0
102- const initialBody = startContext . body
103- if ( initialBody ) {
104- const bodyStr = String ( initialBody )
105- requestBody = truncate ( initialBody , maxRequestSize )
106- requestBodyLength = bodyStr . length // Report the original length before truncating
96+ // Redact request and response headers
97+ const requestHeaders = redactValues ( startContext . headers || { } , redactedKeys )
98+ const responseHeaders = redactValues ( endContext . headers || { } , redactedKeys )
99+
100+ // Truncate request body
101+ let requestBody
102+ let requestBodyLength
103+ if ( startContext . body ) {
104+ requestBody = truncate ( startContext . body , maxRequestSize )
105+ requestBodyLength = startContext . body . length // Report the original length before truncating
107106 }
108107
109- // Extract response headers
110- const responseHeaders = endContext . headers || { }
111-
112- // Extract response body - XHR only
108+ // Truncate response body - XHR only
113109 let responseBody
114110 let responseBodyLength
115- if ( endContext . xhr && endContext . xhr . responseText ) {
116- responseBody = truncate ( endContext . xhr . responseText , maxRequestSize )
117- responseBodyLength = endContext . xhr . responseText . length
111+ if ( endContext . body ) {
112+ responseBody = truncate ( endContext . body , maxRequestSize )
113+ responseBodyLength = endContext . body . length // Report the original length before truncating
118114 }
119115
120116 // Create request and response objects for callback
121117 const requestObj = {
122118 url : redactedUrl ,
123119 httpMethod : method ,
124- headers : redactValues ( requestHeaders , redactedKeys ) ,
120+ headers : requestHeaders ,
125121 params : redactedQueryParams ,
126122 body : requestBody ,
127123 bodyLength : requestBodyLength
128124 }
129125 const responseObj = {
130126 statusCode : endContext . status ,
131- headers : redactValues ( responseHeaders , redactedKeys ) ,
127+ headers : responseHeaders ,
132128 body : responseBody ,
133129 bodyLength : responseBodyLength
134130 }
0 commit comments