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Ac,CAAC,MAAM,GAAa,CAAC,CAAC;AACpC,cAAc,CAAC,MAAM,GAAa,CAAC,CAAC;AACpC,cAAc,CAAC,gBAAgB,GAAG,CAAC,CAAC;AACpC,cAAc,CAAC,OAAO,GAAY,CAAC,CAAC;AACpC,cAAc,CAAC,IAAI,GAAe,CAAC,CAAC;;AAEpC,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC","file":"xhr.js","sourcesContent":["// Implements XMLHttpRequest.\n// See http://www.w3.org/TR/XMLHttpRequest/#the-abort()-method\n\n\nconst DOM     = require('./dom');\nconst Fetch   = require('./fetch');\nconst ms      = require('ms');\nconst URL     = require('url');\nconst Utils   = require('jsdom/lib/jsdom/utils');\nconst EventTarget = require('jsdom/lib/jsdom/living/generated/EventTarget');\n\nconst { DOMException } = DOM;\n\n\nclass XMLHttpRequest {\n//class XMLHttpRequest extends EventTarget {\n\n  constructor(window) {\n    //super();\n    EventTarget.setup(this);\n    for (let method in EventTarget.interface.prototype)\n      this[method] = EventTarget.interface.prototype[method];\n\n    this._window      = window;\n    this._browser     = window.browser;\n    // Pending request\n    this._pending     = null;\n    // Response headers\n    this.readyState   = XMLHttpRequest.UNSENT;\n\n    this.onreadystatechange = null;\n    this.timeout      = 0;\n\n    // XHR events need the first to dispatch, the second to propagate up to window\n    this._ownerDocument = window.document;\n  }\n\n\n  // Aborts the request if it has already been sent.\n  abort() {\n    const request = this._pending;\n    const sent    = !!request;\n    if (this.readyState === XMLHttpRequest.UNSENT || (this.readyState === XMLHttpRequest.OPENED && !sent)) {\n      this.readyState = XMLHttpRequest.UNSENT;\n      return;\n    }\n    // Aborting a done request sets its readyState to UNSENT and does not trigger a readystatechange event\n    // https://xhr.spec.whatwg.org/#the-abort()-method\n    if (this.readyState === XMLHttpRequest.DONE) {\n      this.readyState = XMLHttpRequest.UNSENT;\n    } else {\n      // Tell any pending request it has been aborted.\n      request.aborted = true;\n    }\n    this._response  = null;\n    this._error     = null;\n    this._pending   = null;\n  }\n\n\n  // Initializes a request.\n  //\n  // Calling this method an already active request (one for which open()or\n  // openRequest()has already been called) is the equivalent of calling abort().\n  open(method, url, useAsync, user, password) { // jshint ignore:line\n    if (useAsync === false)\n      throw new DOMException(DOMException.NOT_SUPPORTED_ERR, 'Zombie does not support synchronous XHR requests');\n\n    // Abort any pending request.\n    this.abort();\n\n    // Check supported HTTP method\n    this._method = method.toUpperCase();\n    if (/^(CONNECT|TRACE|TRACK)$/.test(this._method))\n      throw new DOMException(DOMException.SECURITY_ERR, 'Unsupported HTTP method');\n    if (!/^(DELETE|GET|HEAD|OPTIONS|POST|PUT)$/.test(this._method))\n      throw new DOMException(DOMException.SYNTAX_ERR, 'Unsupported HTTP method');\n\n    const headers = new Fetch.Headers();\n\n    // Normalize the URL and check security\n    url = URL.parse(Utils.resolveHref(this._window.location.href, url));\n    // Don't consider port if they are standard for http and https\n    if ((url.protocol === 'https:' && url.port === '443') ||\n        (url.protocol === 'http:'  && url.port === '80'))\n      delete url.port;\n\n    if (!/^https?:$/i.test(url.protocol))\n      throw new DOMException(DOMException.NOT_SUPPORTED_ERR, 'Only HTTP/S protocol supported');\n    url.hostname = url.hostname || this._window.location.hostname;\n    url.host = url.port ? `${url.hostname}:${url.port}` : url.hostname;\n    if (url.host !== this._window.location.host) {\n      headers.set('Origin', `${this._window.location.protocol}//${this._window.location.host}`);\n      this._cors = headers.get('Origin');\n    }\n    url.hash = null;\n    if (user)\n      url.auth = `${user}:${password}`;\n    // Used for logging requests\n    this._url       = URL.format(url);\n    this._headers   = headers;\n\n    // Reset response status\n    this._stateChanged(XMLHttpRequest.OPENED);\n  }\n\n\n  // Sets the value of an HTTP request header.You must call setRequestHeader()\n  // after open(), but before send().\n  setRequestHeader(header, value) {\n    if (this.readyState !== XMLHttpRequest.OPENED)\n      throw new DOMException(DOMException.INVALID_STATE_ERR,  'Invalid state');\n    this._headers.set(header, value);\n  }\n\n\n  // Sends the request. If the request is asynchronous (which is the default),\n  // this method returns as soon as the request is sent. If the request is\n  // synchronous, this method doesn't return until the response has arrived.\n  send(data) {\n    // Request must be opened.\n    if (this.readyState !== XMLHttpRequest.OPENED)\n      throw new DOMException(DOMException.INVALID_STATE_ERR,  'Invalid state');\n\n    const request = new Fetch.Request(this._url, {\n      method:   this._method,\n      headers:  this._headers,\n      body:     data\n    });\n    this._pending = request;\n    this._fire('loadstart');\n\n    const timeout = setTimeout(()=> {\n      if (this._pending === request)\n        this._pending = null;\n      request.timedOut = true;\n\n      this._stateChanged(XMLHttpRequest.DONE);\n      this._fire('progress');\n      this._error = new DOMException(DOMException.TIMEOUT_ERR, 'The request timed out');\n      this._fire('timeout', this._error);\n      this._fire('loadend');\n      this._browser.errors.push(this._error);\n    }, this.timeout || ms('2m'));\n\n    this._window._eventQueue.http(request, (error, response)=> {\n      // Request already timed-out, nothing to do\n      if (request.timedOut)\n        return;\n      clearTimeout(timeout);\n\n      if (this._pending === request)\n        this._pending = null;\n\n      // Request aborted\n      if (request.aborted) {\n        this._stateChanged(XMLHttpRequest.DONE);\n        this._fire('progress');\n        this._error = new DOMException(DOMException.ABORT_ERR, 'Request aborted');\n        this._fire('abort', this._error);\n        return;\n      }\n\n      // If not aborted, then we look at networking error\n      if (error) {\n        this._stateChanged(XMLHttpRequest.DONE);\n        this._fire('progress');\n        this._error = new DOMException(DOMException.NETWORK_ERR);\n        this._fire('error', this._error);\n        this._fire('loadend');\n        this._browser.errors.push(this._error);\n        return;\n      }\n\n      // CORS request, check origin, may lead to new error\n      if (this._cors) {\n        const allowedOrigin = response.headers.get('Access-Control-Allow-Origin');\n        if (!(allowedOrigin === '*' || allowedOrigin === this._cors)) {\n          this._error = new DOMException(DOMException.SECURITY_ERR, 'Cannot make request to different domain');\n          this._browser.errors.push(this._error);\n          this._stateChanged(XMLHttpRequest.DONE);\n          this._fire('progress');\n          this._fire('error', this._error);\n          this._fire('loadend');\n          this.raise('error', this._error.message, { exception: this._error });\n          return;\n        }\n      }\n\n      // Store the response so getters have acess access it\n      this._response        = response;\n      // We have a one-stop implementation that goes through all the state\n      // transitions\n      this._stateChanged(XMLHttpRequest.HEADERS_RECEIVED);\n      this._stateChanged(XMLHttpRequest.LOADING);\n\n      const done = this._window._eventQueue.waitForCompletion();\n      response.text().then(text => {\n        this.responseText = text;\n        this._stateChanged(XMLHttpRequest.DONE);\n\n        this._fire('progress');\n        this._fire('load');\n        this._fire('loadend');\n        done();\n      });\n\n\n    });\n    request.sent = true;\n  }\n\n\n  get status() {\n    // Status code/headers available immediately, 0 if request errored\n    return this._response ? this._response.status :\n           this._error    ? 0 : null;\n  }\n\n  get statusText() {\n    // Status code/headers available immediately, '' if request errored\n    return this._response ? this._response.statusText :\n           this._error    ? '' : null;\n  }\n\n  get responseXML() {\n    // Not implemented yet\n    return null;\n  }\n\n  getResponseHeader(name) {\n    // Returns the string containing the text of the specified header, or null if\n    // either the response has not yet been received or the header doesn't exist in\n    // the response.\n    return this._response && this._response.headers.get(name) || null;\n  }\n\n  getAllResponseHeaders() {\n    // Returns all the response headers as a string, or null if no response has\n    // been received. Note: For multipart requests, this returns the headers from\n    // the current part of the request, not from the original channel.\n    if (this._response)\n      // XHR's getAllResponseHeaders, against all reason, returns a multi-line\n      // string.  See http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders-method\n      return this._response.headers.toString();\n    else\n      return null;\n  }\n\n\n  // Fire onreadystatechange event\n  _stateChanged(newState) {\n    this.readyState = newState;\n    this._fire('readystatechange');\n  }\n\n  // Fire the named event on this object\n  _fire(eventName, error) {\n    const event = new DOM.Event('xhr');\n    event.initEvent(eventName, true, true);\n    event.error = error;\n    this.dispatchEvent(event);\n    this._browser.emit('xhr', eventName, this._url);\n  }\n\n  // Raise error coming from jsdom\n  raise(type, message, data) {\n    this._ownerDocument.raise(type, message, data);\n  }\n\n}\n\n\n// Lifecycle states\nXMLHttpRequest.UNSENT           = 0;\nXMLHttpRequest.OPENED           = 1;\nXMLHttpRequest.HEADERS_RECEIVED = 2;\nXMLHttpRequest.LOADING          = 3;\nXMLHttpRequest.DONE             = 4;\n\nmodule.exports = XMLHttpRequest;\n\n"]}