Skip to content

Commit

Permalink
Remove stream reuse check
Browse files Browse the repository at this point in the history
Fixes #1803
  • Loading branch information
szmarczak committed Jul 24, 2021
1 parent a9afe86 commit 9ecc5ee
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
7 changes: 0 additions & 7 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
private _downloadedSize: number;
private _uploadedSize: number;
private _stopReading: boolean;
private _startedReading: boolean;
private readonly _pipedServerResponses: Set<ServerResponse>;
private _request?: ClientRequest;
private _responseSize?: number;
Expand Down Expand Up @@ -180,7 +179,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
this._downloadedSize = 0;
this._uploadedSize = 0;
this._stopReading = false;
this._startedReading = false;
this._pipedServerResponses = new Set<ServerResponse>();
this._cannotHaveBody = false;
this._unproxyEvents = noop;
Expand Down Expand Up @@ -435,7 +433,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
let data;
while ((data = response.read()) !== null) {
this._downloadedSize += data.length;
this._startedReading = true;

const progress = this.downloadProgress;

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

pipe<T extends NodeJS.WritableStream>(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);
}
Expand Down
19 changes: 1 addition & 18 deletions test/stream.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 9ecc5ee

Please sign in to comment.