Skip to content

Commit

Permalink
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.
  • Loading branch information
lawrence-forooghian committed Nov 14, 2023
1 parent fbf30e6 commit 1d35274
Show file tree
Hide file tree
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
Expand Up @@ -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>;
Expand All @@ -26,7 +26,6 @@ export interface IHttp {
supportsAuthHeaders: boolean;
supportsLinkHeaders: boolean;
agent?: Agents | null;
options: NormalisedClientOptions;

Request?: (
method: HttpMethods,
Expand Down
14 changes: 7 additions & 7 deletions src/platform/nodejs/lib/util/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions src/platform/web/lib/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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);
};
Expand Down

0 comments on commit 1d35274

Please sign in to comment.