diff --git a/lib/__test__/index.test.ts b/lib/__test__/index.test.ts index 0ec5352a..a6840ef2 100644 --- a/lib/__test__/index.test.ts +++ b/lib/__test__/index.test.ts @@ -26,6 +26,7 @@ beforeAll(() => { afterAll(() => { server.close(); + uninstallHacks(); }); describe("tsw index", () => { diff --git a/lib/core/runtime/capture/__test__/incoming.test.ts b/lib/core/runtime/capture/__test__/incoming.test.ts index 2eca6b0a..134e0168 100644 --- a/lib/core/runtime/capture/__test__/incoming.test.ts +++ b/lib/core/runtime/capture/__test__/incoming.test.ts @@ -46,6 +46,7 @@ describe("capture response function test", () => { path: "/", method: "POST", headers: { + Connection: "Close", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": Buffer.byteLength(data) } diff --git a/lib/core/runtime/capture/incoming.ts b/lib/core/runtime/capture/incoming.ts index fb153ea3..79d3c153 100644 --- a/lib/core/runtime/capture/incoming.ts +++ b/lib/core/runtime/capture/incoming.ts @@ -45,10 +45,17 @@ export const captureReadableStream = ( info.bodyTooLarge = info.bodyLength > maxBodySize; }; - let { head } = (stream as any).readableBuffer; - while (head) { - handler(head.data); - head = head.next; + const rb = (stream as any).readableBuffer; + let { head } = rb; + if (head !== undefined) { + while (head) { + handler(head.data); + head = head.next; + } + } else if (rb.forEach) { + rb.forEach((c) => { + handler(c); + }); } (stream as any).push = (chunk: any, encoding?: string): boolean => {