Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/utils/http_request_handler/request_handler.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
import http from 'http';
import https from 'https';
import url from 'url';
import { AbortableRequest, Headers, RequestHandler, Response } from './http';
import decompressResponse from 'decompress-response';
import { LoggerFacade } from '../../logging/logger';
Expand Down Expand Up @@ -46,7 +45,15 @@ export class NodeRequestHandler implements RequestHandler {
* @returns AbortableRequest contains both the response Promise and capability to abort()
*/
makeRequest(requestUrl: string, headers: Headers, method: string, data?: string): AbortableRequest {
const parsedUrl = url.parse(requestUrl);
let parsedUrl: URL;
try {
parsedUrl = new URL(requestUrl);
} catch {
return {
Comment thread
junaed-optimizely marked this conversation as resolved.
responsePromise: Promise.reject(new OptimizelyError(UNSUPPORTED_PROTOCOL, requestUrl)),
abort: () => {},
};
Comment thread
junaed-optimizely marked this conversation as resolved.
}

if (parsedUrl.protocol !== 'https:' && parsedUrl.protocol !== 'http:') {
return {
Expand Down Expand Up @@ -79,11 +86,11 @@ export class NodeRequestHandler implements RequestHandler {
* @private
* @returns http.RequestOptions Standard request options dictionary compatible with both http and https
*/
private getRequestOptionsFromUrl(url: url.UrlWithStringQuery): http.RequestOptions {
private getRequestOptionsFromUrl(url: URL): http.RequestOptions {
return {
hostname: url.hostname,
path: url.path,
port: url.port,
path: url.pathname + url.search,
port: url.port || null,
protocol: url.protocol,
Comment thread
junaed-optimizely marked this conversation as resolved.
Comment on lines 91 to 94
};
}
Expand Down
Loading