Skip to content

Commit c241c71

Browse files
authored
fix(incoming): 解决存量缓冲内容读取失败问题 (#573)
* fix(incoming): 解决存量缓冲内容读取失败问题 * fix(index): 测试完需要清理hack逻辑
1 parent d95de97 commit c241c71

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/__test__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ beforeAll(() => {
2626

2727
afterAll(() => {
2828
server.close();
29+
uninstallHacks();
2930
});
3031

3132
describe("tsw index", () => {

lib/core/runtime/capture/__test__/incoming.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe("capture response function test", () => {
4646
path: "/",
4747
method: "POST",
4848
headers: {
49+
Connection: "Close",
4950
"Content-Type": "application/x-www-form-urlencoded",
5051
"Content-Length": Buffer.byteLength(data)
5152
}

lib/core/runtime/capture/incoming.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ export const captureReadableStream = (
4545
info.bodyTooLarge = info.bodyLength > maxBodySize;
4646
};
4747

48-
let { head } = (stream as any).readableBuffer;
49-
while (head) {
50-
handler(head.data);
51-
head = head.next;
48+
const rb = (stream as any).readableBuffer;
49+
let { head } = rb;
50+
if (head !== undefined) {
51+
while (head) {
52+
handler(head.data);
53+
head = head.next;
54+
}
55+
} else if (rb.forEach) {
56+
rb.forEach((c) => {
57+
handler(c);
58+
});
5259
}
5360

5461
(stream as any).push = (chunk: any, encoding?: string): boolean => {

0 commit comments

Comments
 (0)