Skip to content

Commit c458c5a

Browse files
[FSSDK-12865] url parse fix
1 parent 44828e6 commit c458c5a

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

lib/utils/http_request_handler/request_handler.node.ts

Lines changed: 12 additions & 5 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';
@@ -46,7 +45,15 @@ export class NodeRequestHandler implements RequestHandler {
4645
* @returns AbortableRequest contains both the response Promise and capability to abort()
4746
*/
4847
makeRequest(requestUrl: string, headers: Headers, method: string, data?: string): AbortableRequest {
49-
const parsedUrl = url.parse(requestUrl);
48+
let parsedUrl: URL;
49+
try {
50+
parsedUrl = new URL(requestUrl);
51+
} catch {
52+
return {
53+
responsePromise: Promise.reject(new OptimizelyError(UNSUPPORTED_PROTOCOL, requestUrl)),
54+
abort: () => {},
55+
};
56+
}
5057

5158
if (parsedUrl.protocol !== 'https:' && parsedUrl.protocol !== 'http:') {
5259
return {
@@ -79,11 +86,11 @@ export class NodeRequestHandler implements RequestHandler {
7986
* @private
8087
* @returns http.RequestOptions Standard request options dictionary compatible with both http and https
8188
*/
82-
private getRequestOptionsFromUrl(url: url.UrlWithStringQuery): http.RequestOptions {
89+
private getRequestOptionsFromUrl(url: URL): http.RequestOptions {
8390
return {
8491
hostname: url.hostname,
85-
path: url.path,
86-
port: url.port,
92+
path: url.pathname + url.search,
93+
port: url.port || null,
8794
protocol: url.protocol,
8895
};
8996
}

0 commit comments

Comments
 (0)