DefaultHttpClient.js 2.4 KB

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