fix node20 bug

This commit is contained in:
Sebastian 2023-07-10 09:43:08 -03:00
parent e0c4c2155f
commit f6b63a691b
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069

View File

@ -21,6 +21,7 @@
*/
import * as http from "node:http";
import * as https from "node:https";
import * as net from "node:net";
import { RequestOptions } from "node:http";
import { TalerError } from "./errors.js";
import { encodeBody, getDefaultHeaders, HttpLibArgs } from "./http-common.js";
@ -39,6 +40,19 @@ import {
URL,
} from "./index.js";
// Work around a node v20.0.0, v20.1.0, and v20.2.0 bug. The issue was fixed
// in v20.3.0.
// https://github.com/nodejs/node/issues/47822#issuecomment-1564708870
// Safe to remove once support for Node v20 is dropped.
if (
// check for `node` in case we want to use this in "exotic" JS envs
process.versions.node &&
process.versions.node.match(/20\.[0-2]\.0/)
) {
//@ts-ignore
net.setDefaultAutoSelectFamily(false);
}
const logger = new Logger("http-impl.node.ts");
const textDecoder = new TextDecoder();
@ -126,6 +140,7 @@ export class HttpLibImpl implements HttpRequestLibrary {
method: method,
path,
headers: requestHeadersMap,
timeout: timeoutMs,
};
const chunks: Uint8Array[] = [];