Skip to content

Commit 9ecc5ee

Browse files
committed
Remove stream reuse check
Fixes #1803
1 parent a9afe86 commit 9ecc5ee

File tree

2 files changed

+1
-25
lines changed

2 files changed

+1
-25
lines changed

source/core/index.ts

-7
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
151151
private _downloadedSize: number;
152152
private _uploadedSize: number;
153153
private _stopReading: boolean;
154-
private _startedReading: boolean;
155154
private readonly _pipedServerResponses: Set<ServerResponse>;
156155
private _request?: ClientRequest;
157156
private _responseSize?: number;
@@ -180,7 +179,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
180179
this._downloadedSize = 0;
181180
this._uploadedSize = 0;
182181
this._stopReading = false;
183-
this._startedReading = false;
184182
this._pipedServerResponses = new Set<ServerResponse>();
185183
this._cannotHaveBody = false;
186184
this._unproxyEvents = noop;
@@ -435,7 +433,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
435433
let data;
436434
while ((data = response.read()) !== null) {
437435
this._downloadedSize += data.length;
438-
this._startedReading = true;
439436

440437
const progress = this.downloadProgress;
441438

@@ -522,10 +519,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
522519
}
523520

524521
pipe<T extends NodeJS.WritableStream>(destination: T, options?: {end?: boolean}): T {
525-
if (this._startedReading) {
526-
throw new Error('Failed to pipe. The response has been emitted already.');
527-
}
528-
529522
if (destination instanceof ServerResponse) {
530523
this._pipedServerResponses.add(destination);
531524
}

test/stream.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {promisify} from 'util';
22
import fs from 'fs';
33
import {Agent as HttpAgent} from 'http';
4-
import stream, {PassThrough as PassThroughStream, Readable as ReadableStream, Writable} from 'stream';
4+
import stream, {Readable as ReadableStream, Writable} from 'stream';
55
import {Readable as Readable2} from 'readable-stream';
66
import test from 'ava';
77
import {Handler} from 'express';
@@ -274,23 +274,6 @@ test('skips proxying headers after server has sent them already', withServer, as
274274
t.is(headers.unicorn, undefined);
275275
});
276276

277-
test('throws when trying to proxy through a closed stream', withServer, async (t, server, got) => {
278-
server.get('/', defaultHandler);
279-
280-
const stream = got.stream('');
281-
const promise = getStream(stream);
282-
283-
stream.once('data', () => {
284-
t.throws(() => {
285-
stream.pipe(new PassThroughStream());
286-
}, {
287-
message: 'Failed to pipe. The response has been emitted already.',
288-
});
289-
});
290-
291-
await promise;
292-
});
293-
294277
test('proxies `content-encoding` header when `options.decompress` is false', withServer, async (t, server, got) => {
295278
server.get('/', defaultHandler);
296279
server.get('/proxy', async (_request, response) => {

0 commit comments

Comments
 (0)