From bf39d2c1c58fb79fbe4ef47d92016dcb4f57b6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=8A=E6=B6=82=E4=BA=BA?= Date: Sun, 9 Jan 2022 22:28:49 +0800 Subject: [PATCH] Fix `nock` compatibility (#1959) Co-authored-by: Sindre Sorhus --- source/core/options.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/core/options.ts b/source/core/options.ts index 1f01b47db..ca7994f3c 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -3,8 +3,9 @@ import {Buffer} from 'node:buffer'; import {promisify, inspect} from 'node:util'; import {URL, URLSearchParams} from 'node:url'; import {checkServerIdentity} from 'node:tls'; -import {request as httpRequest} from 'node:http'; -import {request as httpsRequest} from 'node:https'; +// DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`. +import http from 'node:http'; +import https from 'node:https'; import type {Readable} from 'node:stream'; import type {Socket} from 'node:net'; import type {SecureContextOptions, DetailedPeerCertificate} from 'node:tls'; @@ -2447,10 +2448,10 @@ export default class Options { return http2wrapper.auto as RequestFunction; } - return httpsRequest; + return https.request; } - return httpRequest; + return http.request; } freeze() {