Skip to content

Commit 49c5b6f

Browse files
authored
refactor(NODE-7302): remove dependency on uri.parse() (#4798)
1 parent 287c98a commit 49c5b6f

File tree

1 file changed

+0
-67
lines changed

1 file changed

+0
-67
lines changed

src/utils.ts

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { type EventEmitter } from 'events';
44
import { promises as fs } from 'fs';
55
import * as http from 'http';
66
import { clearTimeout, setTimeout } from 'timers';
7-
import * as url from 'url';
8-
import { URL } from 'url';
97
import { promisify } from 'util';
108

119
import { deserialize, type Document, ObjectId, resolveBSONOptions } from './bson';
@@ -1161,13 +1159,6 @@ export function checkParentDomainMatch(address: string, srvHost: string): void {
11611159
}
11621160
}
11631161

1164-
interface RequestOptions {
1165-
json?: boolean;
1166-
method?: string;
1167-
timeout?: number;
1168-
headers?: http.OutgoingHttpHeaders;
1169-
}
1170-
11711162
/**
11721163
* Perform a get request that returns status and body.
11731164
* @internal
@@ -1200,64 +1191,6 @@ export function get(
12001191
});
12011192
}
12021193

1203-
export async function request(uri: string): Promise<Record<string, any>>;
1204-
export async function request(
1205-
uri: string,
1206-
options?: { json?: true } & RequestOptions
1207-
): Promise<Record<string, any>>;
1208-
export async function request(
1209-
uri: string,
1210-
options?: { json: false } & RequestOptions
1211-
): Promise<string>;
1212-
export async function request(
1213-
uri: string,
1214-
options: RequestOptions = {}
1215-
): Promise<string | Record<string, any>> {
1216-
return await new Promise<string | Record<string, any>>((resolve, reject) => {
1217-
const requestOptions = {
1218-
method: 'GET',
1219-
timeout: 10000,
1220-
json: true,
1221-
...url.parse(uri),
1222-
...options
1223-
};
1224-
1225-
const req = http.request(requestOptions, res => {
1226-
res.setEncoding('utf8');
1227-
1228-
let data = '';
1229-
res.on('data', d => {
1230-
data += d;
1231-
});
1232-
1233-
res.once('end', () => {
1234-
if (options.json === false) {
1235-
resolve(data);
1236-
return;
1237-
}
1238-
1239-
try {
1240-
const parsed = JSON.parse(data);
1241-
resolve(parsed);
1242-
} catch {
1243-
// TODO(NODE-3483)
1244-
reject(new MongoRuntimeError(`Invalid JSON response: "${data}"`));
1245-
}
1246-
});
1247-
});
1248-
1249-
req.once('timeout', () =>
1250-
req.destroy(
1251-
new MongoNetworkTimeoutError(
1252-
`Network request to ${uri} timed out after ${options.timeout} ms`
1253-
)
1254-
)
1255-
);
1256-
req.once('error', error => reject(error));
1257-
req.end();
1258-
});
1259-
}
1260-
12611194
/** @internal */
12621195
export const DOCUMENT_DB_CHECK = /(\.docdb\.amazonaws\.com$)|(\.docdb-elastic\.amazonaws\.com$)/;
12631196
/** @internal */

0 commit comments

Comments
 (0)