Skip to content

Commit ba684e1

Browse files
authored
fix(incoming): 到达最大限制后,不再记录包内容 (#560)
1 parent 218dfc9 commit ba684e1

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/core/runtime/capture/incoming.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ export const captureReadableStream = (
2929
body: Buffer.alloc(0)
3030
};
3131

32+
Object.defineProperty(info, "body", {
33+
// 需要用的时候才拼接buffer
34+
get: () => Buffer.concat(info.bodyChunks)
35+
});
36+
3237
const handler = (chunk: any): void => {
3338
info.bodyLength += Buffer.byteLength(chunk);
39+
// 到达最大限制后,不再记录回包内容
40+
if (info.bodyTooLarge) {
41+
return;
42+
}
43+
3444
info.bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
35-
info.body = Buffer.concat(info.bodyChunks);
3645
info.bodyTooLarge = info.bodyLength > maxBodySize;
3746
};
3847

lib/core/runtime/capture/outgoing.ts

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export const captureOutgoing = (outgoing: http.OutgoingMessage): void => {
3030
callback = callbackOrUndefined;
3131
}
3232

33+
// 达到最大长度限制,不再收集包内容
34+
if (bodyLength > maxBodySize) {
35+
return fn.apply(outgoing, [data, encoding, callback]);
36+
}
37+
3338
const buffer = ((): Buffer => {
3439
if (Buffer.isBuffer(data)) {
3540
return data;

lib/core/runtime/create-server.hack.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import * as http from "http";
1010
import * as https from "https";
1111
import * as domain from "domain";
12-
import currentContext, { Context, RequestLog } from "../context";
12+
import { Context, RequestLog } from "../context";
1313
import { address } from "ip";
1414
import { AddressInfo, isIP } from "net";
1515
import { captureOutgoing } from "./capture/outgoing";

0 commit comments

Comments
 (0)