45 lines
1.9 KiB
JavaScript
45 lines
1.9 KiB
JavaScript
"use strict";
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.DefaultHttpClient = void 0;
|
|
const Errors_1 = require("./Errors");
|
|
const FetchHttpClient_1 = require("./FetchHttpClient");
|
|
const HttpClient_1 = require("./HttpClient");
|
|
const Utils_1 = require("./Utils");
|
|
const XhrHttpClient_1 = require("./XhrHttpClient");
|
|
/** Default implementation of {@link @microsoft/signalr.HttpClient}. */
|
|
class DefaultHttpClient extends HttpClient_1.HttpClient {
|
|
/** Creates a new instance of the {@link @microsoft/signalr.DefaultHttpClient}, using the provided {@link @microsoft/signalr.ILogger} to log messages. */
|
|
constructor(logger) {
|
|
super();
|
|
if (typeof fetch !== "undefined" || Utils_1.Platform.isNode) {
|
|
this._httpClient = new FetchHttpClient_1.FetchHttpClient(logger);
|
|
}
|
|
else if (typeof XMLHttpRequest !== "undefined") {
|
|
this._httpClient = new XhrHttpClient_1.XhrHttpClient(logger);
|
|
}
|
|
else {
|
|
throw new Error("No usable HttpClient found.");
|
|
}
|
|
}
|
|
/** @inheritDoc */
|
|
send(request) {
|
|
// Check that abort was not signaled before calling send
|
|
if (request.abortSignal && request.abortSignal.aborted) {
|
|
return Promise.reject(new Errors_1.AbortError());
|
|
}
|
|
if (!request.method) {
|
|
return Promise.reject(new Error("No method defined."));
|
|
}
|
|
if (!request.url) {
|
|
return Promise.reject(new Error("No url defined."));
|
|
}
|
|
return this._httpClient.send(request);
|
|
}
|
|
getCookieString(url) {
|
|
return this._httpClient.getCookieString(url);
|
|
}
|
|
}
|
|
exports.DefaultHttpClient = DefaultHttpClient;
|
|
//# sourceMappingURL=DefaultHttpClient.js.map
|