From 42d8c5d9670835929f59473df0c8a313e37e6f2b Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Wed, 12 Nov 2025 10:20:27 +0600 Subject: [PATCH 1/2] [FSSDK-12027] support http in NodeRequestHandler --- .../request_handler.node.spec.ts | 17 +++++++++++++---- .../request_handler.node.ts | 9 +++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/utils/http_request_handler/request_handler.node.spec.ts b/lib/utils/http_request_handler/request_handler.node.spec.ts index 1865df88b..fc8c3c650 100644 --- a/lib/utils/http_request_handler/request_handler.node.spec.ts +++ b/lib/utils/http_request_handler/request_handler.node.spec.ts @@ -147,12 +147,21 @@ describe('NodeRequestHandler', () => { scope.done(); }); - it('should throw error for a URL with http protocol (not https)', async () => { - const invalidHttpProtocolUrl = 'http://some.example.com'; + it('should handle a URL with http protocol', async () => { + const httpProtocolUrl = 'http://some.example.com'; + const scope = nock(httpProtocolUrl) + .get('/') + .reply(200, body); - const request = nodeRequestHandler.makeRequest(invalidHttpProtocolUrl, {}, 'get'); + const request = nodeRequestHandler.makeRequest(httpProtocolUrl, {}, 'get'); + const response = await request.responsePromise; - await expect(request.responsePromise).rejects.toThrow(); + expect(response).toEqual({ + statusCode: 200, + body, + headers: {}, + }); + scope.done(); }); it('should returns a rejected response promise when the URL protocol is unsupported', async () => { diff --git a/lib/utils/http_request_handler/request_handler.node.ts b/lib/utils/http_request_handler/request_handler.node.ts index 16af94caf..365d0294e 100644 --- a/lib/utils/http_request_handler/request_handler.node.ts +++ b/lib/utils/http_request_handler/request_handler.node.ts @@ -46,14 +46,15 @@ export class NodeRequestHandler implements RequestHandler { makeRequest(requestUrl: string, headers: Headers, method: string, data?: string): AbortableRequest { const parsedUrl = url.parse(requestUrl); - if (parsedUrl.protocol !== 'https:') { + if (parsedUrl.protocol !== 'https:' && parsedUrl.protocol !== 'http:') { return { responsePromise: Promise.reject(new OptimizelyError(UNSUPPORTED_PROTOCOL, parsedUrl.protocol)), abort: () => {}, }; } - const request = https.request({ + const requestModule = parsedUrl.protocol === 'https:' ? https : http; + const request = requestModule.request({ ...this.getRequestOptionsFromUrl(parsedUrl), method, headers: { @@ -77,9 +78,9 @@ export class NodeRequestHandler implements RequestHandler { * Parses a URL into its constituent parts * @param url URL object to parse * @private - * @returns https.RequestOptions Standard request options dictionary + * @returns http.RequestOptions Standard request options dictionary compatible with both http and https */ - private getRequestOptionsFromUrl(url: url.UrlWithStringQuery): https.RequestOptions { + private getRequestOptionsFromUrl(url: url.UrlWithStringQuery): http.RequestOptions { return { hostname: url.hostname, path: url.path, From 42740dfe827609e8d9c1bf7b749873ed01d9b3fc Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Wed, 12 Nov 2025 20:36:08 +0600 Subject: [PATCH 2/2] cr --- lib/utils/http_request_handler/request_handler.node.spec.ts | 2 +- lib/utils/http_request_handler/request_handler.node.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/http_request_handler/request_handler.node.spec.ts b/lib/utils/http_request_handler/request_handler.node.spec.ts index fc8c3c650..33f190676 100644 --- a/lib/utils/http_request_handler/request_handler.node.spec.ts +++ b/lib/utils/http_request_handler/request_handler.node.spec.ts @@ -1,5 +1,5 @@ /** - * Copyright 2022, 2024, Optimizely + * Copyright 2022, 2024-2025, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/utils/http_request_handler/request_handler.node.ts b/lib/utils/http_request_handler/request_handler.node.ts index 365d0294e..520a8f3ed 100644 --- a/lib/utils/http_request_handler/request_handler.node.ts +++ b/lib/utils/http_request_handler/request_handler.node.ts @@ -1,5 +1,5 @@ /** - * Copyright 2022-2023 Optimizely + * Copyright 2022-2023, 2025 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.