Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make IHttpStatic’s constructor options param optional
Browse files Browse the repository at this point in the history
To correctly reflect the fact that the tests instantiate Platform.Http
without any arguments.
lawrence-forooghian committed Nov 8, 2023
1 parent 2341e26 commit f19d52f
Showing 3 changed files with 13 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/common/types/http.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ export type RequestCallback = (
export type RequestParams = Record<string, string> | null;

export interface IHttpStatic {
new (options: NormalisedClientOptions): IHttp;
new (options?: NormalisedClientOptions): IHttp;
methods: Array<HttpMethods>;
methodsWithBody: Array<HttpMethods>;
methodsWithoutBody: Array<HttpMethods>;
@@ -26,7 +26,6 @@ export interface IHttp {
supportsAuthHeaders: boolean;
supportsLinkHeaders: boolean;
agent?: Agents | null;
options: NormalisedClientOptions;

Request?: (
method: HttpMethods,
14 changes: 7 additions & 7 deletions src/platform/nodejs/lib/util/http.ts
Original file line number Diff line number Diff line change
@@ -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,
13 changes: 5 additions & 8 deletions src/platform/web/lib/http/http.ts
Original file line number Diff line number Diff line change
@@ -45,14 +45,11 @@ const Http: IHttpStatic = class {
static methodsWithoutBody = [HttpMethods.Get, HttpMethods.Delete];
static methodsWithBody = [HttpMethods.Post, HttpMethods.Put, HttpMethods.Patch];
checksInProgress: Array<StandardCallback<boolean>> | 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);
};

0 comments on commit f19d52f

Please sign in to comment.