diff --git a/packages/large-response-middleware/src/index.ts b/packages/large-response-middleware/src/index.ts index efc3f16..c0242d6 100644 --- a/packages/large-response-middleware/src/index.ts +++ b/packages/large-response-middleware/src/index.ts @@ -60,7 +60,7 @@ export const withLargeResponseHandler = ({ : ''; const payload = (handlerRequestContext?.response?.body ?? '') + responseHeadersString; - const aproxContentLengthBytes = payload.length * 1.0; + const aproxContentLengthBytes = Buffer.byteLength(payload, 'utf8'); const contentLengthMB = aproxContentLengthBytes > 0 ? aproxContentLengthBytes / TO_MB_FACTOR : 0.0; const sizeLimitInMB = (_sizeLimitInMB ?? LIMIT_REQUEST_SIZE_MB) * 1.0; const thresholdWarnInMB = (thresholdWarn ?? 0.0) * 1.0 * sizeLimitInMB; diff --git a/packages/large-response-middleware/tsconfig.json b/packages/large-response-middleware/tsconfig.json index 74e6b1c..d612497 100644 --- a/packages/large-response-middleware/tsconfig.json +++ b/packages/large-response-middleware/tsconfig.json @@ -6,7 +6,7 @@ "moduleResolution": "node", "lib": ["ESNext"], "sourceMap": true, - "types": ["vitest/globals"], + "types": ["vitest/globals", "node"], "strict": true, "strictFunctionTypes": true, "noImplicitReturns": true,