Skip to content

Commit 8e32375

Browse files
committed
fix: remove deprecated url.parse
1 parent 82b3a70 commit 8e32375

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/utils/http_request_handler/request_handler.node.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
import http from 'http';
1717
import https from 'https';
18-
import url from 'url';
1918
import { AbortableRequest, Headers, RequestHandler, Response } from './http';
2019
import decompressResponse from 'decompress-response';
2120
import { LoggerFacade } from '../../logging/logger';
@@ -27,7 +26,6 @@ import { Platform } from '../../platform_support';
2726
* Handles sending requests and receiving responses over HTTP via NodeJS http module
2827
*/
2928

30-
3129
export class NodeRequestHandler implements RequestHandler {
3230
private readonly logger?: LoggerFacade;
3331
private readonly timeout: number;
@@ -46,7 +44,7 @@ export class NodeRequestHandler implements RequestHandler {
4644
* @returns AbortableRequest contains both the response Promise and capability to abort()
4745
*/
4846
makeRequest(requestUrl: string, headers: Headers, method: string, data?: string): AbortableRequest {
49-
const parsedUrl = url.parse(requestUrl);
47+
const parsedUrl = new URL(requestUrl);
5048

5149
if (parsedUrl.protocol !== 'https:' && parsedUrl.protocol !== 'http:') {
5250
return {
@@ -62,7 +60,7 @@ export class NodeRequestHandler implements RequestHandler {
6260
headers: {
6361
...headers,
6462
'accept-encoding': 'gzip,deflate',
65-
'content-length': String(data?.length || 0)
63+
'content-length': String(data?.length || 0),
6664
},
6765
timeout: this.timeout,
6866
});
@@ -82,11 +80,11 @@ export class NodeRequestHandler implements RequestHandler {
8280
* @private
8381
* @returns http.RequestOptions Standard request options dictionary compatible with both http and https
8482
*/
85-
private getRequestOptionsFromUrl(url: url.UrlWithStringQuery): http.RequestOptions {
83+
private getRequestOptionsFromUrl(url: URL): http.RequestOptions {
8684
return {
8785
hostname: url.hostname,
88-
path: url.path,
89-
port: url.port,
86+
path: url.pathname + url.search,
87+
port: url.port || null,
9088
protocol: url.protocol,
9189
};
9290
}

0 commit comments

Comments
 (0)