From 9ecc5ee76f77aafd5100520d9d8789c491c8fb24 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Sat, 24 Jul 2021 21:03:52 +0200 Subject: [PATCH] Remove stream reuse check Fixes #1803 --- source/core/index.ts | 7 ------- test/stream.ts | 19 +------------------ 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/source/core/index.ts b/source/core/index.ts index b725985a9..262d05b5d 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -151,7 +151,6 @@ export default class Request extends Duplex implements RequestEvents { private _downloadedSize: number; private _uploadedSize: number; private _stopReading: boolean; - private _startedReading: boolean; private readonly _pipedServerResponses: Set; private _request?: ClientRequest; private _responseSize?: number; @@ -180,7 +179,6 @@ export default class Request extends Duplex implements RequestEvents { this._downloadedSize = 0; this._uploadedSize = 0; this._stopReading = false; - this._startedReading = false; this._pipedServerResponses = new Set(); this._cannotHaveBody = false; this._unproxyEvents = noop; @@ -435,7 +433,6 @@ export default class Request extends Duplex implements RequestEvents { let data; while ((data = response.read()) !== null) { this._downloadedSize += data.length; - this._startedReading = true; const progress = this.downloadProgress; @@ -522,10 +519,6 @@ export default class Request extends Duplex implements RequestEvents { } pipe(destination: T, options?: {end?: boolean}): T { - if (this._startedReading) { - throw new Error('Failed to pipe. The response has been emitted already.'); - } - if (destination instanceof ServerResponse) { this._pipedServerResponses.add(destination); } diff --git a/test/stream.ts b/test/stream.ts index c956591d4..b63ed8c6e 100644 --- a/test/stream.ts +++ b/test/stream.ts @@ -1,7 +1,7 @@ import {promisify} from 'util'; import fs from 'fs'; import {Agent as HttpAgent} from 'http'; -import stream, {PassThrough as PassThroughStream, Readable as ReadableStream, Writable} from 'stream'; +import stream, {Readable as ReadableStream, Writable} from 'stream'; import {Readable as Readable2} from 'readable-stream'; import test from 'ava'; import {Handler} from 'express'; @@ -274,23 +274,6 @@ test('skips proxying headers after server has sent them already', withServer, as t.is(headers.unicorn, undefined); }); -test('throws when trying to proxy through a closed stream', withServer, async (t, server, got) => { - server.get('/', defaultHandler); - - const stream = got.stream(''); - const promise = getStream(stream); - - stream.once('data', () => { - t.throws(() => { - stream.pipe(new PassThroughStream()); - }, { - message: 'Failed to pipe. The response has been emitted already.', - }); - }); - - await promise; -}); - test('proxies `content-encoding` header when `options.decompress` is false', withServer, async (t, server, got) => { server.get('/', defaultHandler); server.get('/proxy', async (_request, response) => {