From 2252536eb815d63555c8c9a3d2b6228a8b027d83 Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 19 May 2020 12:51:11 -0700 Subject: [PATCH] Remove extra ts file --- .../clients/ts/signalr/src/NodeHttpClient.ts | 100 ------------------ 1 file changed, 100 deletions(-) delete mode 100644 src/SignalR/clients/ts/signalr/src/NodeHttpClient.ts diff --git a/src/SignalR/clients/ts/signalr/src/NodeHttpClient.ts b/src/SignalR/clients/ts/signalr/src/NodeHttpClient.ts deleted file mode 100644 index 6a9605a5c1..0000000000 --- a/src/SignalR/clients/ts/signalr/src/NodeHttpClient.ts +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -// @ts-ignore: This will be removed from built files and is here to make the types available during dev work -import * as Request from "@types/request"; - -import { AbortError, HttpError, TimeoutError } from "./Errors"; -import { HttpClient, HttpRequest, HttpResponse } from "./HttpClient"; -import { ILogger, LogLevel } from "./ILogger"; -import { isArrayBuffer } from "./Utils"; - -let requestModule: Request.RequestAPI; -if (typeof XMLHttpRequest === "undefined") { - // In order to ignore the dynamic require in webpack builds we need to do this magic - // @ts-ignore: TS doesn't know about these names - const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; - requestModule = requireFunc("request"); -} - -/** @private */ -export class NodeHttpClient extends HttpClient { - private readonly logger: ILogger; - private readonly request: typeof requestModule; - private readonly cookieJar: Request.CookieJar; - - public constructor(logger: ILogger) { - super(); - if (typeof requestModule === "undefined") { - throw new Error("The 'request' module could not be loaded."); - } - - this.logger = logger; - this.cookieJar = requestModule.jar(); - this.request = requestModule.defaults({ jar: this.cookieJar }); - } - - public send(httpRequest: HttpRequest): Promise { - // Check that abort was not signaled before calling send - if (httpRequest.abortSignal) { - if (httpRequest.abortSignal.aborted) { - return Promise.reject(new AbortError()); - } - } - - return new Promise((resolve, reject) => { - - let requestBody: Buffer | string; - if (isArrayBuffer(httpRequest.content)) { - requestBody = Buffer.from(httpRequest.content); - } else { - requestBody = httpRequest.content || ""; - } - - const currentRequest = this.request(httpRequest.url!, { - body: requestBody, - // If binary is expected 'null' should be used, otherwise for text 'utf8' - encoding: httpRequest.responseType === "arraybuffer" ? null : "utf8", - headers: { - // Tell auth middleware to 401 instead of redirecting - "X-Requested-With": "XMLHttpRequest", - ...httpRequest.headers, - }, - method: httpRequest.method, - timeout: httpRequest.timeout, - }, - (error, response, body) => { - if (httpRequest.abortSignal) { - httpRequest.abortSignal.onabort = null; - } - - if (error) { - if (error.code === "ETIMEDOUT") { - this.logger.log(LogLevel.Warning, `Timeout from HTTP request.`); - reject(new TimeoutError()); - } - this.logger.log(LogLevel.Warning, `Error from HTTP request. ${error}`); - reject(error); - return; - } - - if (response.statusCode >= 200 && response.statusCode < 300) { - resolve(new HttpResponse(response.statusCode, response.statusMessage || "", body)); - } else { - reject(new HttpError(response.statusMessage || "", response.statusCode || 0)); - } - }); - - if (httpRequest.abortSignal) { - httpRequest.abortSignal.onabort = () => { - currentRequest.abort(); - reject(new AbortError()); - }; - } - }); - } - - public getCookieString(url: string): string { - return this.cookieJar.getCookieString(url); - } -}