@jaypie/express 1.2.4-rc8 → 1.2.4-rc9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,10 +11,10 @@ export declare class LambdaResponseBuffered extends Writable {
|
|
|
11
11
|
readonly socket: {
|
|
12
12
|
remoteAddress: string;
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
_chunks: Buffer[];
|
|
15
|
+
_headers: Map<string, string | string[]>;
|
|
16
|
+
_headersSent: boolean;
|
|
17
|
+
_resolve: ((result: LambdaResponse) => void) | null;
|
|
18
18
|
constructor();
|
|
19
19
|
getResult(): Promise<LambdaResponse>;
|
|
20
20
|
setHeader(name: string, value: number | string | string[]): this;
|
|
@@ -53,7 +53,7 @@ export declare class LambdaResponseBuffered extends Writable {
|
|
|
53
53
|
_write(chunk: Buffer | string, encoding: BufferEncoding, // eslint-disable-line no-undef
|
|
54
54
|
callback: (error?: Error | null) => void): void;
|
|
55
55
|
_final(callback: (error?: Error | null) => void): void;
|
|
56
|
-
|
|
56
|
+
buildResult(): LambdaResponse;
|
|
57
57
|
private isBinaryContentType;
|
|
58
58
|
}
|
|
59
59
|
export default LambdaResponseBuffered;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -192,6 +192,8 @@ class LambdaResponseBuffered extends node_stream.Writable {
|
|
|
192
192
|
this.socket = {
|
|
193
193
|
remoteAddress: "127.0.0.1",
|
|
194
194
|
};
|
|
195
|
+
// Internal state exposed for direct manipulation by safe response methods
|
|
196
|
+
// that need to bypass dd-trace interception of stream methods
|
|
195
197
|
this._chunks = [];
|
|
196
198
|
this._headers = new Map();
|
|
197
199
|
this._headersSent = false;
|
|
@@ -1295,21 +1297,32 @@ const logger$1 = logger$2.log;
|
|
|
1295
1297
|
// Helpers - Safe response methods to bypass dd-trace interception
|
|
1296
1298
|
//
|
|
1297
1299
|
/**
|
|
1298
|
-
* Check if response is a Lambda mock response with direct
|
|
1300
|
+
* Check if response is a Lambda mock response with direct internal access.
|
|
1299
1301
|
*/
|
|
1300
1302
|
function isLambdaMockResponse(res) {
|
|
1301
|
-
|
|
1303
|
+
const mock = res;
|
|
1304
|
+
return (mock._headers instanceof Map &&
|
|
1305
|
+
Array.isArray(mock._chunks) &&
|
|
1306
|
+
typeof mock.buildResult === "function");
|
|
1302
1307
|
}
|
|
1303
1308
|
/**
|
|
1304
1309
|
* Safely send a JSON response, avoiding dd-trace interception.
|
|
1305
|
-
* For Lambda mock responses, directly
|
|
1310
|
+
* For Lambda mock responses, directly manipulates internal state instead of
|
|
1311
|
+
* using stream methods (write/end) which dd-trace intercepts.
|
|
1306
1312
|
*/
|
|
1307
1313
|
function safeSendJson(res, statusCode, data) {
|
|
1308
1314
|
if (isLambdaMockResponse(res)) {
|
|
1309
|
-
// Direct
|
|
1315
|
+
// Direct internal state manipulation - bypasses dd-trace completely
|
|
1310
1316
|
res._headers.set("content-type", "application/json");
|
|
1311
1317
|
res.statusCode = statusCode;
|
|
1312
|
-
|
|
1318
|
+
// Directly push to chunks array instead of using stream write/end
|
|
1319
|
+
const chunk = Buffer.from(JSON.stringify(data));
|
|
1320
|
+
res._chunks.push(chunk);
|
|
1321
|
+
res._headersSent = true;
|
|
1322
|
+
// Signal completion if a promise is waiting
|
|
1323
|
+
if (res._resolve) {
|
|
1324
|
+
res._resolve(res.buildResult());
|
|
1325
|
+
}
|
|
1313
1326
|
return;
|
|
1314
1327
|
}
|
|
1315
1328
|
// Fall back to standard Express methods for real responses
|
|
@@ -1317,17 +1330,21 @@ function safeSendJson(res, statusCode, data) {
|
|
|
1317
1330
|
}
|
|
1318
1331
|
/**
|
|
1319
1332
|
* Safely send a response body, avoiding dd-trace interception.
|
|
1320
|
-
* For Lambda mock responses, directly
|
|
1333
|
+
* For Lambda mock responses, directly manipulates internal state instead of
|
|
1334
|
+
* using stream methods (write/end) which dd-trace intercepts.
|
|
1321
1335
|
*/
|
|
1322
1336
|
function safeSend(res, statusCode, body) {
|
|
1323
1337
|
if (isLambdaMockResponse(res)) {
|
|
1324
|
-
// Direct
|
|
1338
|
+
// Direct internal state manipulation - bypasses dd-trace completely
|
|
1325
1339
|
res.statusCode = statusCode;
|
|
1326
1340
|
if (body !== undefined) {
|
|
1327
|
-
|
|
1341
|
+
const chunk = Buffer.from(body);
|
|
1342
|
+
res._chunks.push(chunk);
|
|
1328
1343
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1344
|
+
res._headersSent = true;
|
|
1345
|
+
// Signal completion if a promise is waiting
|
|
1346
|
+
if (res._resolve) {
|
|
1347
|
+
res._resolve(res.buildResult());
|
|
1331
1348
|
}
|
|
1332
1349
|
return;
|
|
1333
1350
|
}
|