11/**
2- * Copyright 2022-2023 Optimizely
2+ * Copyright 2022-2023, 2025 Optimizely
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -46,14 +46,15 @@ export class NodeRequestHandler implements RequestHandler {
4646 makeRequest ( requestUrl : string , headers : Headers , method : string , data ?: string ) : AbortableRequest {
4747 const parsedUrl = url . parse ( requestUrl ) ;
4848
49- if ( parsedUrl . protocol !== 'https:' ) {
49+ if ( parsedUrl . protocol !== 'https:' && parsedUrl . protocol !== 'http:' ) {
5050 return {
5151 responsePromise : Promise . reject ( new OptimizelyError ( UNSUPPORTED_PROTOCOL , parsedUrl . protocol ) ) ,
5252 abort : ( ) => { } ,
5353 } ;
5454 }
5555
56- const request = https . request ( {
56+ const requestModule = parsedUrl . protocol === 'https:' ? https : http ;
57+ const request = requestModule . request ( {
5758 ...this . getRequestOptionsFromUrl ( parsedUrl ) ,
5859 method,
5960 headers : {
@@ -77,9 +78,9 @@ export class NodeRequestHandler implements RequestHandler {
7778 * Parses a URL into its constituent parts
7879 * @param url URL object to parse
7980 * @private
80- * @returns https .RequestOptions Standard request options dictionary
81+ * @returns http .RequestOptions Standard request options dictionary compatible with both http and https
8182 */
82- private getRequestOptionsFromUrl ( url : url . UrlWithStringQuery ) : https . RequestOptions {
83+ private getRequestOptionsFromUrl ( url : url . UrlWithStringQuery ) : http . RequestOptions {
8384 return {
8485 hostname : url . hostname ,
8586 path : url . path ,
0 commit comments