text: /** @hidden */
  function createXMLHttpRequest() {
      // If running in Babylon Native, then defer to the native XMLHttpRequest, which has the same public contract
      if (typeof _native !== 'undefined' && _native.XMLHttpRequest) {
          return new _native.XMLHttpRequest();
      }
      else {
          return new XMLHttpRequest();
      }
  }
  /**
   * Extended version of XMLHttpRequest with support for customizations (headers, ...)
   */
  var WebRequest = /** @class */ (function () {
      function WebRequest() {
          this._xhr = createXMLHttpRequest();
      }
      WebRequest.prototype._injectCustomRequestHeaders = function () {
          for (var key in WebRequest.CustomRequestHeaders) {
              var val = WebRequest.CustomRequestHeaders[key];
              if (val) {
                  this._xhr.setRequestHeader(key, val);
              }
          }
      };
      Object.defineProperty(WebRequest.prototype, "onprogress", {
          /**
           * Gets or sets a function to be called when loading progress changes
           */
          get: function () {
              return this._xhr.onprogress;
          },
          set: function (value) {
              this._xhr.onprogress = value;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(WebRequest.prototype, "readyState", {
          /**
           * Returns client's state
           */
          get: function () {
              return this._xhr.readyState;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(WebRequest.prototype, "status", {
          /**
           * Returns client's status
           */
          get: function () {
              return this._xhr.status;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(WebRequest.prototype, "statusText", {
          /**
           * Returns client's status as a text
           */
          get: function () {
              return this._xhr.statusText;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(WebRequest.prototype, "response", {
          /**
           * Returns client's response
           */
          get: function () {
              return this._xhr.response;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(WebRequest.prototype, "responseURL", {
          /**
           * Returns client's response url
           */
          get: function () {
              return this._xhr.responseURL;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(WebRequest.prototype, "responseText", {
          /**
           * Returns client's response as text
           */
          get: function () {
              return this._xhr.responseText;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(WebRequest.prototype, "responseType", {
          /**
           * Gets or sets the expected response type
           */
          get: function () {
              return this._xhr.responseType;
          },
          set: function (value) {
              this._xhr.responseType = value;
          },
          enumerable: false,
          configurable: true
      });
      WebRequest.prototype.addEventListener = function (type, listener, options) {
          this._xhr.addEventListener(type, listener, options);
      };
      WebRequest.prototype.removeEventListener = function (type, listener, options) {
          this._xhr.removeEventListener(type, listener, options);
      };
      /**
       * Cancels any network activity
       */
      WebRequest.prototype.abort = function () {
          this._xhr.abort();
      };
      /**
       * Initiates the request. The optional argument provides the request body. The argument is ignored if request method is GET or HEAD
       * @param body defines an optional request body
       */
      WebRequest.prototype.send = function (body) {
          if (WebRequest.CustomRequestHeaders) {
              this._injectCustomRequestHeaders();
          }
          this._xhr.send(body);
      };
      /**
       * Sets the request method, request URL
       * @param method defines the method to use (GET, POST, etc..)
       * @param url defines the url to connect with
       */
      WebRequest.prototype.open = function (method, url) {
          for (var _i = 0, _a = WebRequest.CustomRequestModifiers; _i < _a.length; _i++) {
              var update = _a[_i];
              update(this._xhr, url);
          }
          // Clean url
          url = url.replace("file:http:", "http:");
          url = url.replace("file:https:", "https:");
          return this._xhr.open(method, url, true);
      };
      /**
       * Sets the value of a request header.
       * @param name The name of the header whose value is to be set
       * @param value The value to set as the body of the header
       */
      WebRequest.prototype.setRequestHeader = function (name, value) {
          this._xhr.setRequestHeader(name, value);
      };
      /**
       * Get the string containing the text of a particular header's value.
       * @param name The name of the header
       * @returns The string containing the text of the given header name
       */
      WebRequest.prototype.getResponseHeader = function (name) {
          return this._xhr.getResponseHeader(name);
      };
      /**
       * Custom HTTP Request Headers to be sent with XMLHttpRequests
       * i.e. when loading files, where the server/service expects an Authorization header
       */
      WebRequest.CustomRequestHeaders = {};
      /**
       * Add callback functions in this array to update all the requests before they get sent to the network
       */
      WebRequest.CustomRequestModifiers = new Array();
      return WebRequest;
  }());
  export { WebRequest };
  //# sourceMappingURL=webRequest.js.map