Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(incoming): 到达最大限制后,不再记录回包内容 #560

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/core/runtime/capture/incoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@
body: Buffer.alloc(0)
};

Object.defineProperty(info, "body", {
// 需要用的时候才拼接buffer
get: () => Buffer.concat(info.bodyChunks)
});

const handler = (chunk: any): void => {
info.bodyLength += Buffer.byteLength(chunk);
// 到达最大限制后,不再记录回包内容
if (info.bodyTooLarge) {
return;

Check warning on line 41 in lib/core/runtime/capture/incoming.ts

View check run for this annotation

Codecov / codecov/patch

lib/core/runtime/capture/incoming.ts#L41

Added line #L41 was not covered by tests
}

info.bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
info.body = Buffer.concat(info.bodyChunks);
info.bodyTooLarge = info.bodyLength > maxBodySize;
};

Expand Down
5 changes: 5 additions & 0 deletions lib/core/runtime/capture/outgoing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
callback = callbackOrUndefined;
}

// 达到最大长度限制,不再收集包内容
if (bodyLength > maxBodySize) {
return fn.apply(outgoing, [data, encoding, callback]);

Check warning on line 35 in lib/core/runtime/capture/outgoing.ts

View check run for this annotation

Codecov / codecov/patch

lib/core/runtime/capture/outgoing.ts#L35

Added line #L35 was not covered by tests
}

const buffer = ((): Buffer => {
if (Buffer.isBuffer(data)) {
return data;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/runtime/create-server.hack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as http from "http";
import * as https from "https";
import * as domain from "domain";
import currentContext, { Context, RequestLog } from "../context";
import { Context, RequestLog } from "../context";
import { address } from "ip";
import { AddressInfo, isIP } from "net";
import { captureOutgoing } from "./capture/outgoing";
Expand Down
Loading