diff --git a/src/common/types/http.ts b/src/common/types/http.ts index 404fb6c156..086f55c2d9 100644 --- a/src/common/types/http.ts +++ b/src/common/types/http.ts @@ -16,7 +16,7 @@ export type RequestCallback = ( export type RequestParams = Record | null; export interface IHttpStatic { - new (options: NormalisedClientOptions): IHttp; + new (options?: NormalisedClientOptions): IHttp; methods: Array; methodsWithBody: Array; methodsWithoutBody: Array; @@ -26,7 +26,6 @@ export interface IHttp { supportsAuthHeaders: boolean; supportsLinkHeaders: boolean; agent?: Agents | null; - options: NormalisedClientOptions; Request?: ( method: HttpMethods, diff --git a/src/platform/nodejs/lib/util/http.ts b/src/platform/nodejs/lib/util/http.ts index e24628fcc9..1edeadef17 100644 --- a/src/platform/nodejs/lib/util/http.ts +++ b/src/platform/nodejs/lib/util/http.ts @@ -105,10 +105,10 @@ const Http: IHttpStatic = class { _getHosts = getHosts; supportsAuthHeaders = true; supportsLinkHeaders = true; - options: NormalisedClientOptions; + private options: NormalisedClientOptions | null; - constructor(options: NormalisedClientOptions) { - this.options = options || {}; + constructor(options?: NormalisedClientOptions) { + this.options = options ?? null; } /* Unlike for doUri, the 'client' param here is mandatory, as it's used to generate the hosts */ @@ -235,13 +235,13 @@ const Http: IHttpStatic = class { } checkConnectivity = (callback: (errorInfo: ErrorInfo | null, connected?: boolean) => void): void => { - if (this.options.disableConnectivityCheck) { + if (this.options?.disableConnectivityCheck) { callback(null, true); return; } - const connectivityCheckUrl = this.options.connectivityCheckUrl || Defaults.connectivityCheckUrl; - const connectivityCheckParams = this.options.connectivityCheckParams; - const connectivityUrlIsDefault = !this.options.connectivityCheckUrl; + const connectivityCheckUrl = this.options?.connectivityCheckUrl || Defaults.connectivityCheckUrl; + const connectivityCheckParams = this.options?.connectivityCheckParams ?? null; + const connectivityUrlIsDefault = !this.options?.connectivityCheckUrl; this.doUri( HttpMethods.Get, diff --git a/src/platform/web/lib/http/http.ts b/src/platform/web/lib/http/http.ts index f7dcdd1285..0b6bd62028 100644 --- a/src/platform/web/lib/http/http.ts +++ b/src/platform/web/lib/http/http.ts @@ -45,14 +45,11 @@ const Http: IHttpStatic = class { static methodsWithoutBody = [HttpMethods.Get, HttpMethods.Delete]; static methodsWithBody = [HttpMethods.Post, HttpMethods.Put, HttpMethods.Patch]; checksInProgress: Array> | null = null; - options: NormalisedClientOptions; - constructor(options: NormalisedClientOptions) { - this.options = options || {}; - - const connectivityCheckUrl = this.options.connectivityCheckUrl || Defaults.connectivityCheckUrl; - const connectivityCheckParams = this.options.connectivityCheckParams; - const connectivityUrlIsDefault = !this.options.connectivityCheckUrl; + constructor(options?: NormalisedClientOptions) { + const connectivityCheckUrl = options?.connectivityCheckUrl || Defaults.connectivityCheckUrl; + const connectivityCheckParams = options?.connectivityCheckParams ?? null; + const connectivityUrlIsDefault = !options?.connectivityCheckUrl; if (Platform.Config.xhrSupported) { this.supportsAuthHeaders = true; this.Request = function ( @@ -77,7 +74,7 @@ const Http: IHttpStatic = class { req.exec(); return req; }; - if (this.options.disableConnectivityCheck) { + if (options?.disableConnectivityCheck) { this.checkConnectivity = function (callback: (err: null, connectivity: true) => void) { callback(null, true); };