1515 */
1616import http from 'http' ;
1717import https from 'https' ;
18- import url from 'url' ;
1918import { AbortableRequest , Headers , RequestHandler , Response } from './http' ;
2019import decompressResponse from 'decompress-response' ;
2120import { 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-
3129export 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