Skip to content

Commit 52a1063

Browse files
committedMay 27, 2023
Require Node.js 16
Fixes #989 Fixes #1581
1 parent 1cefe8b commit 52a1063

28 files changed

+338
-350
lines changed
 

‎benchmark/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {URL} from 'node:url';
21
import https from 'node:https';
32
/// import axios from 'axios';
43
import Benchmark from 'benchmark';

‎documentation/3-streams.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,27 @@ This constructor takes the same arguments as the Got promise.
2727
> - If there's no body on purpose, remember to `stream.end()` or set the body option to an empty string.
2828
2929
```js
30-
import {promisify} from 'node:util';
3130
import stream from 'node:stream';
31+
import {pipeline as streamPipeline} from 'node:stream/promises';
3232
import fs from 'node:fs';
3333
import got from 'got';
3434

35-
const pipeline = promisify(stream.pipeline);
36-
3735
// This example streams the GET response of a URL to a file.
38-
await pipeline(
36+
await streamPipeline(
3937
got.stream('https://sindresorhus.com'),
4038
fs.createWriteStream('index.html')
4139
);
4240

4341
// For POST, PUT, PATCH, and DELETE methods, `got.stream` returns a `stream.Writable`.
4442
// This example POSTs the contents of a file to a URL.
45-
await pipeline(
43+
await streamPipeline(
4644
fs.createReadStream('index.html'),
4745
got.stream.post('https://sindresorhus.com'),
4846
new stream.PassThrough()
4947
);
5048

5149
// In order to POST, PUT, PATCH, or DELETE without a request body, explicitly specify an empty body:
52-
await pipeline(
50+
await streamPipeline(
5351
got.stream.post('https://sindresorhus.com', { body: '' }),
5452
new stream.PassThrough()
5553
)
@@ -181,7 +179,7 @@ Whether the socket was used for other previous requests.
181179
This is emitted when a HTTP response is received.
182180

183181
```js
184-
import {pipeline} from 'node:stream/promises';
182+
import {pipeline as streamPipeline} from 'node:stream/promises';
185183
import {createWriteStream} from 'node:fs';
186184
import got from 'got';
187185

@@ -202,7 +200,7 @@ readStream.on('response', async response => {
202200
readStream.off('error', onError);
203201

204202
try {
205-
await pipeline(
203+
await streamPipeline(
206204
readStream,
207205
createWriteStream('image.png')
208206
);

‎documentation/migration-guides/nodejs.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ Well, it's easy as that:
7878

7979
```js
8080
import got from 'got';
81-
import stream from 'node:stream';
81+
import {pipeline as streamPipeline} from 'node:stream/promises';
8282
import fs from 'node:fs';
8383

84-
await stream.promises.pipeline(
84+
await streamPipeline(
8585
fs.createReadStream('article.txt'),
8686
got.stream.post('https://httpbin.org/anything'),
8787
fs.createWriteStream('httpbin.txt')

‎documentation/migration-guides/request.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,12 @@ http.createServer((serverRequest, serverResponse) => {
113113
The cool feature here is that Request can proxy headers with the stream, but Got can do that too!
114114

115115
```js
116-
import {promisify} from 'node:util';
117-
import stream from 'node:stream';
116+
import {pipeline as streamPipeline} from 'node:stream/promises';
118117
import got from 'got';
119118

120-
const pipeline = promisify(stream.pipeline);
121-
122119
const server = http.createServer(async (serverRequest, serverResponse) => {
123120
if (serverRequest.url === '/doodle.png') {
124-
await pipeline(
121+
await streamPipeline(
125122
got.stream('https://example.com/doodle.png'),
126123
serverResponse
127124
);

‎documentation/quick-start.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The [Stream API](3-streams.md) allows to leverage [Node.js Streams](https://node
6565

6666
```js
6767
import fs from 'node:fs';
68-
import {pipeline} from 'node:stream/promises';
68+
import {pipeline as streamPipeline} from 'node:stream/promises';
6969
import got from 'got';
7070

7171
const url = 'https://httpbin.org/anything';
@@ -81,7 +81,7 @@ const gotStream = got.stream.post(url, options);
8181
const outStream = fs.createWriteStream('anything.json');
8282

8383
try {
84-
await pipeline(gotStream, outStream);
84+
await streamPipeline(gotStream, outStream);
8585
} catch (error) {
8686
console.error(error);
8787
}

‎package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"repository": "sindresorhus/got",
77
"funding": "https://github.com/sindresorhus/got?sponsor=1",
88
"type": "module",
9-
"exports": "./dist/source/index.js",
10-
"types": "./dist/source/index.d.ts",
9+
"exports": {
10+
"types": "./dist/source/index.d.ts",
11+
"default": "./dist/source/index.js"
12+
},
1113
"engines": {
12-
"node": ">=14.16"
14+
"node": ">=16"
1315
},
1416
"scripts": {
1517
"test": "xo && tsc --noEmit && ava",
@@ -99,8 +101,8 @@
99101
"tough-cookie": "4.1.2",
100102
"ts-node": "^10.8.2",
101103
"type-fest": "^3.6.1",
102-
"typescript": "~4.9.5",
103-
"xo": "^0.53.1"
104+
"typescript": "^5.0.4",
105+
"xo": "^0.54.2"
104106
},
105107
"sideEffects": false,
106108
"ava": {
@@ -135,8 +137,6 @@
135137
"rules": {
136138
"@typescript-eslint/no-empty-function": "off",
137139
"n/no-deprecated-api": "off",
138-
"n/prefer-global/url": "off",
139-
"n/prefer-global/url-search-params": "off",
140140
"@typescript-eslint/no-implicit-any-catch": "off",
141141
"unicorn/prefer-node-protocol": "off",
142142
"ava/assertion-arguments": "off",
@@ -146,6 +146,8 @@
146146
"@typescript-eslint/no-unsafe-call": "off",
147147
"@typescript-eslint/await-thenable": "off",
148148
"@typescript-eslint/no-redundant-type-constituents": "off",
149+
"@typescript-eslint/no-unsafe-argument": "off",
150+
"@typescript-eslint/promise-function-async": "off",
149151
"no-lone-blocks": "off",
150152
"unicorn/no-await-expression-member": "off"
151153
}

‎source/core/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import process from 'node:process';
22
import {Buffer} from 'node:buffer';
33
import {Duplex, type Readable} from 'node:stream';
4-
import {URL, URLSearchParams} from 'node:url';
54
import http, {ServerResponse} from 'node:http';
65
import type {ClientRequest, RequestOptions} from 'node:http';
76
import type {Socket} from 'node:net';
@@ -46,6 +45,8 @@ import {
4645
AbortError,
4746
} from './errors.js';
4847

48+
const {buffer: getStreamAsBuffer} = getStream;
49+
4950
type Error = NodeJS.ErrnoException;
5051

5152
export type Progress = {
@@ -54,8 +55,6 @@ export type Progress = {
5455
total?: number;
5556
};
5657

57-
const {buffer: getBuffer} = getStream;
58-
5958
const supportsBrotli = is.string(process.versions.brotli);
6059

6160
const methodsWithoutBody: ReadonlySet<string> = new Set(['GET', 'HEAD']);
@@ -176,7 +175,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
176175
private _isFromCache?: boolean;
177176
private _cannotHaveBody: boolean;
178177
private _triggerRead: boolean;
179-
declare private _jobs: Array<() => void>;
178+
declare private readonly _jobs: Array<() => void>;
180179
private _cancelTimeouts: () => void;
181180
private readonly _removeListeners: () => void;
182181
private _nativeResponse?: IncomingMessageWithTimings;
@@ -877,7 +876,11 @@ export default class Request extends Duplex implements RequestEvents<Request> {
877876

878877
try {
879878
// Errors are emitted via the `error` event
880-
const rawBody = await getBuffer(from);
879+
const rawBody = await getStreamAsBuffer(from);
880+
881+
// TODO: Switch to this:
882+
// let rawBody = await from.toArray();
883+
// rawBody = Buffer.concat(rawBody);
881884

882885
// On retry Request is destroyed with no error, therefore the above will successfully resolve.
883886
// So in order to check if this was really successfull, we need to check if it has been properly ended.
@@ -992,7 +995,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
992995
// We only need to implement the error handler in order to support HTTP2 caching.
993996
// The result will be a promise anyway.
994997
// @ts-expect-error ignore
995-
// eslint-disable-next-line @typescript-eslint/promise-function-async
996998
result.once = (event: string, handler: (reason: unknown) => void) => {
997999
if (event === 'error') {
9981000
(async () => {

‎source/core/options.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import process from 'node:process';
22
import type {Buffer} from 'node:buffer';
33
import {promisify, inspect} from 'node:util';
4-
import {URL, URLSearchParams} from 'node:url';
54
import {checkServerIdentity} from 'node:tls';
65
// DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`.
76
import http from 'node:http';
@@ -976,7 +975,7 @@ const init = (options: OptionsInit, withOptions: OptionsInit, self: Options): vo
976975

977976
export default class Options {
978977
private _unixOptions?: NativeRequestOptions;
979-
private _internals: InternalsType;
978+
private readonly _internals: InternalsType;
980979
private _merging: boolean;
981980
private readonly _init: OptionsInit[];
982981

‎source/core/response.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {Buffer} from 'node:buffer';
2-
import type {URL} from 'node:url';
32
import type {IncomingMessageWithTimings, Timings} from '@szmarczak/http-timer';
43
import {RequestError} from './errors.js';
54
import type {ParseJsonFunction, ResponseType} from './options.js';

‎source/core/timed-out.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ export default function timedOut(request: ClientRequest, delays: Delays, options
9090
}
9191
});
9292

93-
if (typeof delays.request !== 'undefined') {
93+
if (delays.request !== undefined) {
9494
const cancelTimeout = addTimeout(delays.request, timeoutHandler, 'request');
9595

9696
once(request, 'response', (response: IncomingMessage): void => {
9797
once(response, 'end', cancelTimeout);
9898
});
9999
}
100100

101-
if (typeof delays.socket !== 'undefined') {
101+
if (delays.socket !== undefined) {
102102
const {socket} = delays;
103103

104104
const socketTimeoutHandler = (): void => {
@@ -115,10 +115,10 @@ export default function timedOut(request: ClientRequest, delays: Delays, options
115115
});
116116
}
117117

118-
const hasLookup = typeof delays.lookup !== 'undefined';
119-
const hasConnect = typeof delays.connect !== 'undefined';
120-
const hasSecureConnect = typeof delays.secureConnect !== 'undefined';
121-
const hasSend = typeof delays.send !== 'undefined';
118+
const hasLookup = delays.lookup !== undefined;
119+
const hasConnect = delays.connect !== undefined;
120+
const hasSecureConnect = delays.secureConnect !== undefined;
121+
const hasSend = delays.send !== undefined;
122122
if (hasLookup || hasConnect || hasSecureConnect || hasSend) {
123123
once(request, 'socket', (socket: net.Socket): void => {
124124
const {socketPath} = request as ClientRequest & {socketPath?: string};
@@ -127,7 +127,7 @@ export default function timedOut(request: ClientRequest, delays: Delays, options
127127
if (socket.connecting) {
128128
const hasPath = Boolean(socketPath ?? net.isIP(hostname ?? host ?? '') !== 0);
129129

130-
if (hasLookup && !hasPath && typeof (socket.address() as net.AddressInfo).address === 'undefined') {
130+
if (hasLookup && !hasPath && (socket.address() as net.AddressInfo).address === undefined) {
131131
const cancelTimeout = addTimeout(delays.lookup!, timeoutHandler, 'lookup');
132132
once(socket, 'lookup', cancelTimeout);
133133
}
@@ -168,14 +168,14 @@ export default function timedOut(request: ClientRequest, delays: Delays, options
168168
});
169169
}
170170

171-
if (typeof delays.response !== 'undefined') {
171+
if (delays.response !== undefined) {
172172
once(request, 'upload-complete', (): void => {
173173
const cancelTimeout = addTimeout(delays.response!, timeoutHandler, 'response');
174174
once(request, 'response', cancelTimeout);
175175
});
176176
}
177177

178-
if (typeof delays.read !== 'undefined') {
178+
if (delays.read !== undefined) {
179179
once(request, 'response', (response: IncomingMessage): void => {
180180
const cancelTimeout = addTimeout(delays.read!, timeoutHandler, 'read');
181181
once(response, 'end', cancelTimeout);

‎source/core/utils/is-unix-socket-url.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type {URL} from 'url';
2-
31
// eslint-disable-next-line @typescript-eslint/naming-convention
42
export default function isUnixSocketURL(url: URL) {
53
return url.protocol === 'unix:' || url.hostname === 'unix';

‎source/core/utils/options-to-url.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* istanbul ignore file: deprecated */
2-
import {URL} from 'node:url';
3-
41
// eslint-disable-next-line @typescript-eslint/naming-convention
52
export type URLOptions = {
63
href?: string;

‎source/core/utils/url-to-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {URL, UrlWithStringQuery} from 'node:url';
1+
import type {UrlWithStringQuery} from 'node:url';
22
import is from '@sindresorhus/is';
33

44
// TODO: Deprecate legacy URL at some point

‎source/create.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type {URL} from 'node:url';
21
import is, {assert} from '@sindresorhus/is';
32
import asPromise from './as-promise/index.js';
43
import type {

‎source/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {Buffer} from 'node:buffer';
2-
import type {URL} from 'node:url';
32
import type {CancelableRequest} from './as-promise/types.js';
43
import type {Response} from './core/response.js';
54
import type Options from './core/options.js';

‎test/abort.ts

+231-234
Large diffs are not rendered by default.

‎test/arguments.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {parse, URL, URLSearchParams} from 'url';
1+
import {parse} from 'url';
22
import test from 'ava';
33
import type {Handler} from 'express';
44
import {pEvent} from 'p-event';

‎test/cancel.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import process from 'process';
22
import {EventEmitter} from 'events';
3-
import stream, {Readable as ReadableStream} from 'stream';
3+
import {Readable as ReadableStream} from 'stream';
4+
import {pipeline as streamPipeline} from 'stream/promises';
45
import test from 'ava';
56
import delay from 'delay';
67
import {pEvent} from 'p-event';
@@ -54,13 +55,16 @@ const downloadHandler = (clock?: GlobalClock): Handler => (_request, response) =
5455

5556
response.flushHeaders();
5657

57-
stream.pipeline(
58-
slowDataStream(clock),
59-
response,
60-
() => {
61-
response.end();
62-
},
63-
);
58+
(async () => {
59+
try {
60+
await streamPipeline(
61+
slowDataStream(clock),
62+
response,
63+
);
64+
} catch {}
65+
66+
response.end();
67+
})();
6468
};
6569

6670
test.serial('does not retry after cancelation', withServerAndFakeTimers, async (t, server, got, clock) => {

‎test/create.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
type IncomingMessage,
55
type RequestOptions,
66
} from 'http';
7-
import {URL} from 'url';
87
import test from 'ava';
98
import is from '@sindresorhus/is';
109
import type {Handler} from 'express';

‎test/error.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {Buffer} from 'buffer';
2-
import {URL} from 'url';
32
import {promisify} from 'util';
43
import net from 'net';
54
import http from 'http';
65
import stream from 'stream';
6+
import {pipeline as streamPipeline} from 'stream/promises';
77
import test from 'ava';
88
import getStream from 'get-stream';
99
import is from '@sindresorhus/is';
@@ -12,8 +12,6 @@ import type Request from '../source/core/index.js';
1212
import withServer from './helpers/with-server.js';
1313
import invalidUrl from './helpers/invalid-url.js';
1414

15-
const pStreamPipeline = promisify(stream.pipeline);
16-
1715
test('properties', withServer, async (t, server, got) => {
1816
server.get('/', (_request, response) => {
1917
response.statusCode = 404;
@@ -57,7 +55,7 @@ test('`options.body` form error message', async t => {
5755

5856
test('no plain object restriction on json body', withServer, async (t, server, got) => {
5957
server.post('/body', async (request, response) => {
60-
await pStreamPipeline(request, response);
58+
await streamPipeline(request, response);
6159
});
6260

6361
class CustomObject {

‎test/hooks.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Buffer} from 'buffer';
2-
import {URL} from 'url';
32
import {Agent as HttpAgent} from 'http';
43
import test from 'ava';
54
import nock from 'nock';

‎test/normalize-arguments.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {URL, URLSearchParams} from 'url';
21
import test from 'ava';
32
import got, {Options} from '../source/index.js';
43

‎test/pagination.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Buffer} from 'buffer';
2-
import {URL} from 'url';
32
import test from 'ava';
43
import delay from 'delay';
54
import getStream from 'get-stream';

‎test/post.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import process from 'process';
22
import {Buffer} from 'buffer';
3-
import {promisify} from 'util';
43
import stream from 'stream';
4+
import {pipeline as streamPipeline} from 'stream/promises';
55
import fs from 'fs';
66
import fsPromises from 'fs/promises';
77
import path from 'path';
@@ -17,11 +17,9 @@ import FormData from 'form-data';
1717
import got, {UploadError} from '../source/index.js';
1818
import withServer from './helpers/with-server.js';
1919

20-
const pStreamPipeline = promisify(stream.pipeline);
21-
2220
const defaultEndpoint: Handler = async (request, response) => {
2321
response.setHeader('method', request.method);
24-
await pStreamPipeline(request, response);
22+
await streamPipeline(request, response);
2523
};
2624

2725
const echoHeaders: Handler = (request, response) => {

‎test/progress.ts

+32-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import process from 'process';
22
import {Buffer} from 'buffer';
33
import {promisify} from 'util';
44
import stream from 'stream';
5+
import {pipeline as streamPipeline} from 'node:stream/promises';
56
import fs from 'fs';
67
// @ts-expect-error Fails to find slow-stream/index.d.ts
78
import SlowStream from 'slow-stream';
@@ -49,14 +50,17 @@ const file = Buffer.alloc(1024 * 1024 * 2);
4950
const downloadEndpoint: Handler = (_request, response) => {
5051
response.setHeader('content-length', file.length);
5152

52-
stream.pipeline(
53-
stream.Readable.from(file),
54-
new SlowStream({maxWriteInterval: 50}),
55-
response,
56-
() => {
57-
response.end();
58-
},
59-
);
53+
(async () => {
54+
try {
55+
await streamPipeline(
56+
stream.Readable.from(file),
57+
new SlowStream({maxWriteInterval: 50}),
58+
response,
59+
);
60+
} catch {}
61+
62+
response.end();
63+
})();
6064
};
6165

6266
const noTotalEndpoint: Handler = (_request, response) => {
@@ -65,13 +69,16 @@ const noTotalEndpoint: Handler = (_request, response) => {
6569
};
6670

6771
const uploadEndpoint: Handler = (request, response) => {
68-
stream.pipeline(
69-
request,
70-
new SlowStream({maxWriteInterval: 100}),
71-
() => {
72-
response.end();
73-
},
74-
);
72+
(async () => {
73+
try {
74+
await streamPipeline(
75+
request,
76+
new SlowStream({maxWriteInterval: 100}),
77+
);
78+
} catch {}
79+
80+
response.end();
81+
})();
7582
};
7683

7784
test('download progress', withServer, async (t, server, got) => {
@@ -177,11 +184,12 @@ test('upload progress - stream with known body size', withServer, async (t, serv
177184
};
178185

179186
const request = got.stream.post(options)
180-
.on('uploadProgress', event => events.push(event));
187+
.on('uploadProgress', event => {
188+
events.push(event);
189+
});
181190

182-
await getStream(
183-
stream.pipeline(stream.Readable.from(file), request, () => {}),
184-
);
191+
await streamPipeline(stream.Readable.from(file), request);
192+
await getStream(request);
185193

186194
checkEvents(t, events, file.length);
187195
});
@@ -192,11 +200,12 @@ test('upload progress - stream with unknown body size', withServer, async (t, se
192200
const events: Progress[] = [];
193201

194202
const request = got.stream.post('')
195-
.on('uploadProgress', event => events.push(event));
203+
.on('uploadProgress', event => {
204+
events.push(event);
205+
});
196206

197-
await getStream(
198-
stream.pipeline(stream.Readable.from(file), request, () => {}),
199-
);
207+
await streamPipeline(stream.Readable.from(file), request);
208+
await getStream(request);
200209

201210
t.is(events[0]?.total, undefined);
202211
checkEvents(t, events);

‎test/stream.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import process from 'process';
22
import {Buffer} from 'buffer';
3-
import {promisify} from 'util';
43
import fs from 'fs';
54
import {Agent as HttpAgent} from 'http';
65
import stream, {Readable as ReadableStream, Writable} from 'stream';
6+
import {pipeline as streamPipeline} from 'stream/promises';
77
import {Readable as Readable2} from 'readable-stream';
88
import test from 'ava';
99
import type {Handler} from 'express';
@@ -15,8 +15,6 @@ import delay from 'delay';
1515
import got, {HTTPError, RequestError} from '../source/index.js';
1616
import withServer from './helpers/with-server.js';
1717

18-
const pStreamPipeline = promisify(stream.pipeline);
19-
2018
const defaultHandler: Handler = (_request, response) => {
2119
response.writeHead(200, {
2220
unicorn: 'rainbow',
@@ -33,7 +31,7 @@ const redirectHandler: Handler = (_request, response) => {
3331
};
3432

3533
const postHandler: Handler = async (request, response) => {
36-
await pStreamPipeline(request, response);
34+
await streamPipeline(request, response);
3735
};
3836

3937
const errorHandler: Handler = (_request, response) => {
@@ -196,7 +194,7 @@ test('piping works', withServer, async (t, server, got) => {
196194
test('proxying headers works', withServer, async (t, server, got) => {
197195
server.get('/', defaultHandler);
198196
server.get('/proxy', async (_request, response) => {
199-
await pStreamPipeline(
197+
await streamPipeline(
200198
got.stream(''),
201199
response,
202200
);
@@ -211,7 +209,7 @@ test('proxying headers works', withServer, async (t, server, got) => {
211209
test('piping server request to Got proxies also headers', withServer, async (t, server, got) => {
212210
server.get('/', headersHandler);
213211
server.get('/proxy', async (request, response) => {
214-
await pStreamPipeline(
212+
await streamPipeline(
215213
request,
216214
got.stream(''),
217215
response,
@@ -231,7 +229,7 @@ test('skips proxying headers after server has sent them already', withServer, as
231229
server.get('/proxy', async (_request, response) => {
232230
response.writeHead(200);
233231

234-
await pStreamPipeline(
232+
await streamPipeline(
235233
got.stream(''),
236234
response,
237235
);
@@ -244,7 +242,7 @@ test('skips proxying headers after server has sent them already', withServer, as
244242
test('proxies `content-encoding` header when `options.decompress` is false', withServer, async (t, server, got) => {
245243
server.get('/', defaultHandler);
246244
server.get('/proxy', async (_request, response) => {
247-
await pStreamPipeline(
245+
await streamPipeline(
248246
got.stream({decompress: false}),
249247
response,
250248
);
@@ -286,13 +284,14 @@ test('piping to got.stream.put()', withServer, async (t, server, got) => {
286284
server.put('/post', postHandler);
287285

288286
await t.notThrowsAsync(async () => {
289-
await getStream(
290-
stream.pipeline(
291-
got.stream(''),
292-
got.stream.put('post'),
293-
() => {},
294-
),
287+
const stream = got.stream.put('post');
288+
289+
await streamPipeline(
290+
got.stream(''),
291+
stream,
295292
);
293+
294+
await getStream(stream);
296295
});
297296
});
298297

@@ -310,7 +309,7 @@ test.skip('no unhandled body stream errors', async t => {
310309
});
311310

312311
test('works with pipeline', async t => {
313-
await t.throwsAsync(pStreamPipeline(
312+
await t.throwsAsync(streamPipeline(
314313
new ReadableStream({
315314
read() {
316315
this.push(null);
@@ -369,7 +368,7 @@ test('the socket is alive on a successful pipeline', withServer, async (t, serve
369368
t.is(gotStream.socket, undefined);
370369

371370
const receiver = new stream.PassThrough();
372-
await promisify(stream.pipeline)(gotStream, receiver);
371+
await streamPipeline(gotStream, receiver);
373372

374373
t.is(await getStream(receiver), payload);
375374
t.truthy(gotStream.socket);

‎test/timeout.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import process from 'process';
2-
import {promisify} from 'util';
32
import {EventEmitter} from 'events';
43
import stream, {PassThrough as PassThroughStream} from 'stream';
4+
import {pipeline as streamPipeline} from 'stream/promises';
55
import http from 'http';
66
import net from 'net';
77
import getStream from 'get-stream';
@@ -16,8 +16,6 @@ import slowDataStream from './helpers/slow-data-stream.js';
1616
import type {GlobalClock} from './helpers/types.js';
1717
import withServer, {withServerAndFakeTimers, withHttpsServer} from './helpers/with-server.js';
1818

19-
const pStreamPipeline = promisify(stream.pipeline);
20-
2119
const requestDelay = 800;
2220

2321
const errorMatcher = {
@@ -44,7 +42,7 @@ const downloadHandler = (clock?: GlobalClock): Handler => (_request, response) =
4442
response.flushHeaders();
4543

4644
setImmediate(async () => {
47-
await pStreamPipeline(slowDataStream(clock), response);
45+
await streamPipeline(slowDataStream(clock), response);
4846
});
4947
};
5048

‎test/url-to-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {parse as urlParse, URL} from 'url';
1+
import {parse as urlParse} from 'url';
22
import test from 'ava';
33
import urlToOptions from '../source/core/utils/url-to-options.js';
44

0 commit comments

Comments
 (0)
Please sign in to comment.