Skip to content

Commit ade9240

Browse files
committed
Revert "fix: patch undici File support on Node.js < 20 (#588)"
This reverts commit 0e5ad19.
1 parent 3cc8971 commit ade9240

9 files changed

Lines changed: 9 additions & 56 deletions

src/HttpClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export class HttpClient extends EventEmitter {
429429
const requestOptions: IUndiciRequestOption = {
430430
method,
431431
// disable undici auto redirect handler
432-
// maxRedirections: 0,
432+
maxRedirections: 0,
433433
headersTimeout,
434434
headers,
435435
bodyTimeout,

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { LRU } from 'ylru';
22
import { patchForNode16 } from './utils.js';
33

4-
54
patchForNode16();
65

76
import { HttpClient, HEADER_USER_AGENT } from './HttpClient.js';

src/utils.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { randomBytes, createHash } from 'node:crypto';
22
import { Readable } from 'node:stream';
33
import { performance } from 'node:perf_hooks';
44
import { ReadableStream, TransformStream } from 'node:stream/web';
5-
import { Blob, File } from 'node:buffer';
6-
import { toUSVString } from 'node:util';
5+
import { Blob } from 'node:buffer';
76
import type { FixJSONCtlChars } from './Request.js';
87
import { SocketInfo } from './Response.js';
98
import symbols from './symbols.js';
@@ -232,37 +231,6 @@ export function patchForNode16() {
232231
// @ts-ignore
233232
global.DOMException = getDOMExceptionClass();
234233
}
235-
// multi undici version in node version less than 20 https://github.com/nodejs/undici/issues/4374
236-
if (typeof global.File === 'undefined') {
237-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
238-
// @ts-ignore
239-
global.File = File;
240-
}
241-
242-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
243-
// @ts-ignore
244-
if (String.prototype.toWellFormed === undefined) {
245-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
246-
// @ts-ignore
247-
String.prototype.toWellFormed = function() {
248-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
249-
// @ts-ignore
250-
return toUSVString(this);
251-
};
252-
}
253-
254-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
255-
// @ts-ignore
256-
if (String.prototype.isWellFormed === undefined) {
257-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
258-
// @ts-ignore
259-
String.prototype.isWellFormed = function() {
260-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
261-
// @ts-ignore
262-
return toUSVString(this) === this;
263-
};
264-
}
265-
266234
}
267235

268236
// https://github.com/jimmywarting/node-domexception/blob/main/index.js

test/HttpClient.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import { describe, it, beforeAll, afterAll } from 'vitest';
88
import selfsigned from 'selfsigned';
99
import { HttpClient, RawResponseWithMeta, getGlobalDispatcher } from '../src/index.js';
1010
import { startServer } from './fixtures/server.js';
11-
import { nodeMajorVersion } from './utils.js';
1211

13-
const pems = selfsigned.generate([], {
14-
keySize: nodeMajorVersion() >= 22 ? 2048 : 1024,
15-
});
12+
const pems = selfsigned.generate();
1613

1714
if (process.env.ENABLE_PERF) {
1815
const obs = new PerformanceObserver(items => {

test/diagnostics_channel.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
} from '../src/index.js';
1313
import symbols from '../src/symbols.js';
1414
import { startServer } from './fixtures/server.js';
15-
import { nodeMajorVersion } from './utils.js';
1615

1716
describe('diagnostics_channel.test.ts', () => {
1817
let close: any;
@@ -144,9 +143,7 @@ describe('diagnostics_channel.test.ts', () => {
144143
});
145144

146145
it('should support trace socket info with H2 by undici:client:sendHeaders and undici:request:trailers', async () => {
147-
const pem = selfsigned.generate([], {
148-
keySize: nodeMajorVersion() >= 22 ? 2048 : 1024,
149-
});
146+
const pem = selfsigned.generate();
150147
const server = createSecureServer({
151148
key: pem.private,
152149
cert: pem.cert,

test/fixtures/server.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import busboy from 'busboy';
88
import iconv from 'iconv-lite';
99
import selfsigned from 'selfsigned';
1010
import qs from 'qs';
11-
import { nodeMajorVersion, readableToBytes } from '../utils.js';
11+
import { readableToBytes } from '../utils.js';
1212

1313
const requestsPerSocket = Symbol('requestsPerSocket');
1414

@@ -370,9 +370,7 @@ export async function startServer(options?: {
370370
};
371371

372372
if (options?.https) {
373-
const pem = selfsigned.generate([], {
374-
keySize: nodeMajorVersion() >= 22 ? 2048 : 1024,
375-
});
373+
const pem = selfsigned.generate();
376374
server = createHttpsServer({
377375
key: pem.private,
378376
cert: pem.cert,

test/options.stream.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('options.stream.test.ts', () => {
9494
assert.equal(response.headers['content-type'], 'application/json');
9595
assert.equal(response.data.method, 'POST');
9696
// console.log(response.data);
97-
// assert.match(response.data.headers['content-type'], /^multipart\/form-data; boundary=--------------------------\d+$/);
97+
assert.match(response.data.headers['content-type'], /^multipart\/form-data; boundary=--------------------------\d+$/);
9898
assert.equal(response.data.files.file.filename, 'options.stream.test.ts');
9999
assert.equal(response.data.form.hello, '你好 urllib 3');
100100
const raw = await readFile(__filename);

test/options.timeout.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import selfsigned from 'selfsigned';
55
import { describe, it, beforeAll, afterAll } from 'vitest';
66
import urllib, { HttpClientRequestTimeoutError, HttpClient } from '../src/index.js';
77
import { startServer } from './fixtures/server.js';
8-
import { nodeMajorVersion } from './utils.js';
98

10-
const pems = selfsigned.generate([], {
11-
keySize: nodeMajorVersion() >= 22 ? 2048 : 1024,
12-
});
9+
const pems = selfsigned.generate();
1310

1411
describe('options.timeout.test.ts', () => {
1512
let close: any;

test/urllib.options.rejectUnauthorized-false.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { describe, it, beforeAll, afterAll } from 'vitest';
55
import selfsigned from 'selfsigned';
66
import urllib, { HttpClient } from '../src/index.js';
77
import { startServer } from './fixtures/server.js';
8-
import { nodeMajorVersion } from './utils.js';
98

109
describe('urllib.options.rejectUnauthorized-false.test.ts', () => {
1110
let close: any;
@@ -30,9 +29,7 @@ describe('urllib.options.rejectUnauthorized-false.test.ts', () => {
3029
});
3130

3231
it('should 200 with H2 on options.rejectUnauthorized = false', async () => {
33-
const pem = selfsigned.generate([], {
34-
keySize: nodeMajorVersion() >= 22 ? 2048 : 1024,
35-
});
32+
const pem = selfsigned.generate();
3633
const server = createSecureServer({
3734
key: pem.private,
3835
cert: pem.cert,

0 commit comments

Comments
 (0)