DefaultHttpClient.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. var __extends = (this && this.__extends) || (function () {
  4. var extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return function (d, b) {
  8. extendStatics(d, b);
  9. function __() { this.constructor = d; }
  10. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11. };
  12. })();
  13. import { AbortError } from "./Errors";
  14. import { HttpClient } from "./HttpClient";
  15. import { NodeHttpClient } from "./NodeHttpClient";
  16. import { XhrHttpClient } from "./XhrHttpClient";
  17. /** Default implementation of {@link @aspnet/signalr.HttpClient}. */
  18. var DefaultHttpClient = /** @class */ (function (_super) {
  19. __extends(DefaultHttpClient, _super);
  20. /** Creates a new instance of the {@link @aspnet/signalr.DefaultHttpClient}, using the provided {@link @aspnet/signalr.ILogger} to log messages. */
  21. function DefaultHttpClient(logger) {
  22. var _this = _super.call(this) || this;
  23. if (typeof XMLHttpRequest !== "undefined") {
  24. _this.httpClient = new XhrHttpClient(logger);
  25. }
  26. else {
  27. _this.httpClient = new NodeHttpClient(logger);
  28. }
  29. return _this;
  30. }
  31. /** @inheritDoc */
  32. DefaultHttpClient.prototype.send = function (request) {
  33. // Check that abort was not signaled before calling send
  34. if (request.abortSignal && request.abortSignal.aborted) {
  35. return Promise.reject(new AbortError());
  36. }
  37. if (!request.method) {
  38. return Promise.reject(new Error("No method defined."));
  39. }
  40. if (!request.url) {
  41. return Promise.reject(new Error("No url defined."));
  42. }
  43. return this.httpClient.send(request);
  44. };
  45. DefaultHttpClient.prototype.getCookieString = function (url) {
  46. return this.httpClient.getCookieString(url);
  47. };
  48. return DefaultHttpClient;
  49. }(HttpClient));
  50. export { DefaultHttpClient };
  51. //# sourceMappingURL=DefaultHttpClient.js.map