UNPKG

castelog

Version:

Programación JavaScript en castellano.

1 lines 1.57 MB
"\n\n//Included:lib/000.inicializacion.part.js\n// CASTELOG@0.0.1\n\n/***************************************************************************************\n ***[ Manifiesto de Castelog v.0.0.1 ]**********************************[ 2022/08 ]*****\n ***************************************************************************************\n *** ***\n *** Castelog es un software construido por «allnulled» o «Carlos Jimeno Hernández». ***\n *** ***\n *** No tiene licencia, haz lo que quieras con él. ***\n *** ***\n *************************************************[ Carlos J. / +34 619 98 26 22 ]******\n ******************************************************************************[ ]******\n ***************************************************[ Licencia gratis siempre ya ]******\n ******************************************************************************[ ]******\n ******************************************************************************[ ]******/\n\n////////////////////////////////////////////////////////////////////////////////\n// Aquí empieza el script de Castelog //////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////\n// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n//Included:lib/001.01.xhr2-v.part.js\n/*lib:xhr2 v0.2.1 + modifications*/\n// Generated by CoffeeScript 2.5.1\n(function () {\n const is_nodejs_environment = (typeof global !== \"undefined\") && (typeof require !== \"undefined\");\n if(!is_nodejs_environment) return;\n // This file's name is set up in such a way that it will always show up first in\n // the list of files given to coffee --join, so that the other files can assume\n // that XMLHttpRequestEventTarget was already defined.\n\n // The DOM EventTarget subclass used by XMLHttpRequest.\n\n // @see http://xhr.spec.whatwg.org/#interface-xmlhttprequest\n var InvalidStateError, NetworkError, ProgressEvent, SecurityError, SyntaxError, XMLHttpRequest, XMLHttpRequestEventTarget, XMLHttpRequestUpload, http, https, os, url;\n\n XMLHttpRequestEventTarget = (function () {\n class XMLHttpRequestEventTarget {\n // @private\n // This is an abstract class and should not be instantiated directly.\n constructor() {\n this.onloadstart = null;\n this.onprogress = null;\n this.onabort = null;\n this.onerror = null;\n this.onload = null;\n this.ontimeout = null;\n this.onloadend = null;\n this._listeners = {};\n }\n\n // Adds a new-style listener for one of the XHR events.\n\n // @see http://www.w3.org/TR/XMLHttpRequest/#events\n\n // @param {String} eventType an XHR event type, such as 'readystatechange'\n // @param {function(ProgressEvent)} listener function that will be called when\n // the event fires\n // @return {undefined} undefined\n addEventListener(eventType, listener) {\n var base;\n eventType = eventType.toLowerCase();\n (base = this._listeners)[eventType] || (base[eventType] = []);\n this._listeners[eventType].push(listener);\n return void 0;\n }\n\n // Removes an event listener added by calling addEventListener.\n\n // @param {String} eventType an XHR event type, such as 'readystatechange'\n // @param {function(ProgressEvent)} listener the value passed in a previous\n // call to addEventListener.\n // @return {undefined} undefined\n removeEventListener(eventType, listener) {\n var index;\n eventType = eventType.toLowerCase();\n if (this._listeners[eventType]) {\n index = this._listeners[eventType].indexOf(listener);\n if (index !== -1) {\n this._listeners[eventType].splice(index, 1);\n }\n }\n return void 0;\n }\n\n // Calls all the listeners for an event.\n\n // @param {ProgressEvent} event the event to be dispatched\n // @return {undefined} undefined\n dispatchEvent(event) {\n var eventType, j, len, listener, listeners;\n event.currentTarget = event.target = this;\n eventType = event.type;\n if (listeners = this._listeners[eventType]) {\n for (j = 0, len = listeners.length; j < len; j++) {\n listener = listeners[j];\n listener.call(this, event);\n }\n }\n if (listener = this[`on${eventType}`]) {\n listener.call(this, event);\n }\n return void 0;\n }\n\n };\n\n // @property {function(ProgressEvent)} DOM level 0-style handler\n // for the 'loadstart' event\n XMLHttpRequestEventTarget.prototype.onloadstart = null;\n\n // @property {function(ProgressEvent)} DOM level 0-style handler\n // for the 'progress' event\n XMLHttpRequestEventTarget.prototype.onprogress = null;\n\n // @property {function(ProgressEvent)} DOM level 0-style handler\n // for the 'abort' event\n XMLHttpRequestEventTarget.prototype.onabort = null;\n\n // @property {function(ProgressEvent)} DOM level 0-style handler\n // for the 'error' event\n XMLHttpRequestEventTarget.prototype.onerror = null;\n\n // @property {function(ProgressEvent)} DOM level 0-style handler\n // for the 'load' event\n XMLHttpRequestEventTarget.prototype.onload = null;\n\n // @property {function(ProgressEvent)} DOM level 0-style handler\n // for the 'timeout' event\n XMLHttpRequestEventTarget.prototype.ontimeout = null;\n\n // @property {function(ProgressEvent)} DOM level 0-style handler\n // for the 'loadend' event\n XMLHttpRequestEventTarget.prototype.onloadend = null;\n\n return XMLHttpRequestEventTarget;\n\n }).call(this);\n\n // This file's name is set up in such a way that it will always show up second\n // in the list of files given to coffee --join, so it can use the\n // XMLHttpRequestEventTarget definition and so that the other files can assume\n // that XMLHttpRequest was already defined.\n http = require('http');\n\n https = require('https');\n\n os = require('os');\n\n url = require('url');\n\n XMLHttpRequest = (function () {\n // The ECMAScript HTTP API.\n\n // @see http://www.w3.org/TR/XMLHttpRequest/#introduction\n class XMLHttpRequest extends XMLHttpRequestEventTarget {\n // Creates a new request.\n\n // @param {Object} options one or more of the options below\n // @option options {Boolean} anon if true, the request's anonymous flag\n // will be set\n // @see http://www.w3.org/TR/XMLHttpRequest/#constructors\n // @see http://www.w3.org/TR/XMLHttpRequest/#anonymous-flag\n constructor(options) {\n super();\n this.onreadystatechange = null;\n this._anonymous = options && options.anon;\n this.readyState = XMLHttpRequest.UNSENT;\n this.response = null;\n this.responseText = '';\n this.responseType = '';\n this.responseURL = '';\n this.status = 0;\n this.statusText = '';\n this.timeout = 0;\n this.upload = new XMLHttpRequestUpload(this);\n this._method = null; // String\n this._url = null; // Return value of url.parse()\n this._sync = false;\n this._headers = null; // Object<String, String>\n this._loweredHeaders = null; // Object<lowercase String, String>\n this._mimeOverride = null;\n this._request = null; // http.ClientRequest\n this._response = null; // http.ClientResponse\n this._responseParts = null; // Array<Buffer, String>\n this._responseHeaders = null; // Object<lowercase String, String>\n this._aborting = null;\n this._error = null;\n this._loadedBytes = 0;\n this._totalBytes = 0;\n this._lengthComputable = false;\n }\n\n // Sets the XHR's method, URL, synchronous flag, and authentication params.\n\n // @param {String} method the HTTP method to be used\n // @param {String} url the URL that the request will be made to\n // @param {?Boolean} async if false, the XHR should be processed\n // synchronously; true by default\n // @param {?String} user the user credential to be used in HTTP basic\n // authentication\n // @param {?String} password the password credential to be used in HTTP basic\n // authentication\n // @return {undefined} undefined\n // @throw {SecurityError} method is not one of the allowed methods\n // @throw {SyntaxError} urlString is not a valid URL\n // @throw {Error} the URL contains an unsupported protocol; the supported\n // protocols are file, http and https\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-open()-method\n open(method, url, async, user, password) {\n var xhrUrl;\n method = method.toUpperCase();\n if (method in this._restrictedMethods) {\n throw new SecurityError(`HTTP method ${method} is not allowed in XHR`);\n }\n xhrUrl = this._parseUrl(url);\n if (async === void 0) {\n async = true;\n }\n switch (this.readyState) {\n case XMLHttpRequest.UNSENT:\n case XMLHttpRequest.OPENED:\n case XMLHttpRequest.DONE:\n // Nothing to do here.\n null;\n break;\n case XMLHttpRequest.HEADERS_RECEIVED:\n case XMLHttpRequest.LOADING:\n // TODO(pwnall): terminate abort(), terminate send()\n null;\n }\n this._method = method;\n this._url = xhrUrl;\n this._sync = !async;\n this._headers = {};\n this._loweredHeaders = {};\n this._mimeOverride = null;\n this._setReadyState(XMLHttpRequest.OPENED);\n this._request = null;\n this._response = null;\n this.status = 0;\n this.statusText = '';\n this._responseParts = [];\n this._responseHeaders = null;\n this._loadedBytes = 0;\n this._totalBytes = 0;\n this._lengthComputable = false;\n return void 0;\n }\n\n // Appends a header to the list of author request headers.\n\n // @param {String} name the HTTP header name\n // @param {String} value the HTTP header value\n // @return {undefined} undefined\n // @throw {InvalidStateError} readyState is not OPENED\n // @throw {SyntaxError} name is not a valid HTTP header name or value is not\n // a valid HTTP header value\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader()-method\n setRequestHeader(name, value) {\n var loweredName;\n if (this.readyState !== XMLHttpRequest.OPENED) {\n throw new InvalidStateError(\"XHR readyState must be OPENED\");\n }\n loweredName = name.toLowerCase();\n if (this._restrictedHeaders[loweredName] || /^sec\\-/.test(loweredName) || /^proxy-/.test(loweredName)) {\n console.warn(`Refused to set unsafe header \\\"${name}\\\"`);\n return void 0;\n }\n value = value.toString();\n if (loweredName in this._loweredHeaders) {\n // Combine value with the existing header value.\n name = this._loweredHeaders[loweredName];\n this._headers[name] = this._headers[name] + ', ' + value;\n } else {\n // New header.\n this._loweredHeaders[loweredName] = name;\n this._headers[name] = value;\n }\n return void 0;\n }\n\n // Initiates the request.\n\n // @param {?String, ?ArrayBufferView} data the data to be sent; ignored for\n // GET and HEAD requests\n // @return {undefined} undefined\n // @throw {InvalidStateError} readyState is not OPENED\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-send()-method\n send(data) {\n if (this.readyState !== XMLHttpRequest.OPENED) {\n throw new InvalidStateError(\"XHR readyState must be OPENED\");\n }\n if (this._request) {\n throw new InvalidStateError(\"send() already called\");\n }\n switch (this._url.protocol) {\n case 'file:':\n this._sendFile(data);\n break;\n case 'http:':\n case 'https:':\n this._sendHttp(data);\n break;\n default:\n throw new NetworkError(`Unsupported protocol ${this._url.protocol}`);\n }\n return void 0;\n }\n\n // Cancels the network activity performed by this request.\n\n // @return {undefined} undefined\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-abort()-method\n abort() {\n if (!this._request) {\n return;\n }\n this._request.abort();\n this._setError();\n this._dispatchProgress('abort');\n this._dispatchProgress('loadend');\n return void 0;\n }\n\n // Returns a header value in the HTTP response for this XHR.\n\n // @param {String} name case-insensitive HTTP header name\n // @return {?String} value the value of the header whose name matches the\n // given name, or null if there is no such header\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method\n getResponseHeader(name) {\n var loweredName;\n if (!this._responseHeaders) {\n return null;\n }\n loweredName = name.toLowerCase();\n if (loweredName in this._responseHeaders) {\n return this._responseHeaders[loweredName];\n } else {\n return null;\n }\n }\n\n // Returns all the HTTP headers in this XHR's response.\n\n // @return {String} header lines separated by CR LF, where each header line\n // has the name and value separated by a \": \" (colon, space); the empty\n // string is returned if the headers are not available\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method\n getAllResponseHeaders() {\n var lines, name, value;\n if (!this._responseHeaders) {\n return '';\n }\n lines = (function () {\n var ref, results;\n ref = this._responseHeaders;\n results = [];\n for (name in ref) {\n value = ref[name];\n results.push(`${name}: ${value}`);\n }\n return results;\n }).call(this);\n return lines.join(\"\\r\\n\");\n }\n\n // Overrides the Content-Type\n\n // @return {undefined} undefined\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-overridemimetype()-method\n overrideMimeType(newMimeType) {\n if (this.readyState === XMLHttpRequest.LOADING || this.readyState === XMLHttpRequest.DONE) {\n throw new InvalidStateError(\"overrideMimeType() not allowed in LOADING or DONE\");\n }\n this._mimeOverride = newMimeType.toLowerCase();\n return void 0;\n }\n\n // Network configuration not exposed in the XHR API.\n\n // Although the XMLHttpRequest specification calls itself \"ECMAScript HTTP\",\n // it assumes that requests are always performed in the context of a browser\n // application, where some network parameters are set by the browser user and\n // should not be modified by Web applications. This API provides access to\n // these network parameters.\n\n // NOTE: this is not in the XMLHttpRequest API, and will not work in\n // browsers. It is a stable node-xhr2 API.\n\n // @param {Object} options one or more of the options below\n // @option options {?http.Agent} httpAgent the value for the nodejsHttpAgent\n // property (the agent used for HTTP requests)\n // @option options {?https.Agent} httpsAgent the value for the\n // nodejsHttpsAgent property (the agent used for HTTPS requests)\n // @return {undefined} undefined\n nodejsSet(options) {\n var baseUrl, parsedUrl;\n if ('httpAgent' in options) {\n this.nodejsHttpAgent = options.httpAgent;\n }\n if ('httpsAgent' in options) {\n this.nodejsHttpsAgent = options.httpsAgent;\n }\n if ('baseUrl' in options) {\n baseUrl = options.baseUrl;\n if (baseUrl !== null) {\n parsedUrl = url.parse(baseUrl, false, true);\n if (!parsedUrl.protocol) {\n throw new SyntaxError(\"baseUrl must be an absolute URL\");\n }\n }\n this.nodejsBaseUrl = baseUrl;\n }\n return void 0;\n }\n\n // Default settings for the network configuration not exposed in the XHR API.\n\n // NOTE: this is not in the XMLHttpRequest API, and will not work in\n // browsers. It is a stable node-xhr2 API.\n\n // @param {Object} options one or more of the options below\n // @option options {?http.Agent} httpAgent the default value for the\n // nodejsHttpAgent property (the agent used for HTTP requests)\n // @option options {https.Agent} httpsAgent the default value for the\n // nodejsHttpsAgent property (the agent used for HTTPS requests)\n // @return {undefined} undefined\n // @see XMLHttpRequest.nodejsSet\n static nodejsSet(options) {\n // \"this\" will be set to XMLHttpRequest.prototype, so the instance nodejsSet\n // operates on default property values.\n XMLHttpRequest.prototype.nodejsSet(options);\n return void 0;\n }\n\n // Sets the readyState property and fires the readystatechange event.\n\n // @private\n // @param {Number} newReadyState the new value of readyState\n // @return {undefined} undefined\n _setReadyState(newReadyState) {\n var event;\n this.readyState = newReadyState;\n event = new ProgressEvent('readystatechange');\n this.dispatchEvent(event);\n return void 0;\n }\n\n // XMLHttpRequest#send() implementation for the file: protocol.\n\n // @private\n _sendFile() {\n if (this._url.method !== 'GET') {\n throw new NetworkError('The file protocol only supports GET');\n }\n throw new Error(\"Protocol file: not implemented\");\n }\n\n // XMLHttpRequest#send() implementation for the http: and https: protocols.\n\n // @private\n // This method sets the instance variables and calls _sendHxxpRequest(), which\n // is responsible for building a node.js request and firing it off. The code\n // in _sendHxxpRequest() is separated off so it can be reused when handling\n // redirects.\n\n // @see http://www.w3.org/TR/XMLHttpRequest/#infrastructure-for-the-send()-method\n _sendHttp(data) {\n if (this._sync) {\n throw new Error(\"Synchronous XHR processing not implemented\");\n }\n if ((data != null) && (this._method === 'GET' || this._method === 'HEAD')) {\n console.warn(`Discarding entity body for ${this._method} requests`);\n data = null;\n } else {\n // Send Content-Length: 0\n data || (data = '');\n }\n // NOTE: this is called before finalizeHeaders so that the uploader can\n // figure out Content-Length and Content-Type.\n this.upload._setData(data);\n this._finalizeHeaders();\n this._sendHxxpRequest();\n return void 0;\n }\n\n // Sets up and fires off a HTTP/HTTPS request using the node.js API.\n\n // @private\n // This method contains the bulk of the XMLHttpRequest#send() implementation,\n // and is also used to issue new HTTP requests when handling HTTP redirects.\n\n // @see http://www.w3.org/TR/XMLHttpRequest/#infrastructure-for-the-send()-method\n _sendHxxpRequest() {\n var agent, hxxp, request;\n if (this._url.protocol === 'http:') {\n hxxp = http;\n agent = this.nodejsHttpAgent;\n } else {\n hxxp = https;\n agent = this.nodejsHttpsAgent;\n }\n request = hxxp.request({\n hostname: this._url.hostname,\n port: this._url.port,\n path: this._url.path,\n auth: this._url.auth,\n method: this._method,\n headers: this._headers,\n agent: agent\n });\n this._request = request;\n if (this.timeout) {\n request.setTimeout(this.timeout, () => {\n return this._onHttpTimeout(request);\n });\n }\n request.on('response', (response) => {\n return this._onHttpResponse(request, response);\n });\n request.on('error', (error) => {\n return this._onHttpRequestError(request, error);\n });\n this.upload._startUpload(request);\n if (this._request === request) { // An http error might have already fired.\n this._dispatchProgress('loadstart');\n }\n return void 0;\n }\n\n // Fills in the restricted HTTP headers with default values.\n\n // This is called right before the HTTP request is sent off.\n\n // @private\n // @return {undefined} undefined\n _finalizeHeaders() {\n var base;\n this._headers['Connection'] = 'keep-alive';\n this._headers['Host'] = this._url.host;\n if (this._anonymous) {\n this._headers['Referer'] = 'about:blank';\n }\n (base = this._headers)['User-Agent'] || (base['User-Agent'] = this._userAgent);\n this.upload._finalizeHeaders(this._headers, this._loweredHeaders);\n return void 0;\n }\n\n // Called when the headers of an HTTP response have been received.\n\n // @private\n // @param {http.ClientRequest} request the node.js ClientRequest instance that\n // produced this response\n // @param {http.ClientResponse} response the node.js ClientResponse instance\n // passed to\n _onHttpResponse(request, response) {\n var lengthString;\n if (this._request !== request) {\n return;\n }\n // Transparent redirection handling.\n switch (response.statusCode) {\n case 301:\n case 302:\n case 303:\n case 307:\n case 308:\n this._url = this._parseUrl(response.headers['location']);\n this._method = 'GET';\n if ('content-type' in this._loweredHeaders) {\n delete this._headers[this._loweredHeaders['content-type']];\n delete this._loweredHeaders['content-type'];\n }\n // XMLHttpRequestUpload#_finalizeHeaders() sets Content-Type directly.\n if ('Content-Type' in this._headers) {\n delete this._headers['Content-Type'];\n }\n // Restricted headers can't be set by the user, no need to check\n // loweredHeaders.\n delete this._headers['Content-Length'];\n this.upload._reset();\n this._finalizeHeaders();\n this._sendHxxpRequest();\n return;\n }\n this._response = response;\n this._response.on('data', (data) => {\n return this._onHttpResponseData(response, data);\n });\n this._response.on('end', () => {\n return this._onHttpResponseEnd(response);\n });\n this._response.on('close', () => {\n return this._onHttpResponseClose(response);\n });\n this.responseURL = this._url.href.split('#')[0];\n this.status = this._response.statusCode;\n this.statusText = http.STATUS_CODES[this.status];\n this._parseResponseHeaders(response);\n if (lengthString = this._responseHeaders['content-length']) {\n this._totalBytes = parseInt(lengthString);\n this._lengthComputable = true;\n } else {\n this._lengthComputable = false;\n }\n return this._setReadyState(XMLHttpRequest.HEADERS_RECEIVED);\n }\n\n // Called when some data has been received on a HTTP connection.\n\n // @private\n // @param {http.ClientResponse} response the node.js ClientResponse instance\n // that fired this event\n // @param {String, Buffer} data the data that has been received\n _onHttpResponseData(response, data) {\n if (this._response !== response) {\n return;\n }\n this._responseParts.push(data);\n this._loadedBytes += data.length;\n if (this.readyState !== XMLHttpRequest.LOADING) {\n this._setReadyState(XMLHttpRequest.LOADING);\n }\n return this._dispatchProgress('progress');\n }\n\n // Called when the HTTP request finished processing.\n\n // @private\n // @param {http.ClientResponse} response the node.js ClientResponse instance\n // that fired this event\n _onHttpResponseEnd(response) {\n if (this._response !== response) {\n return;\n }\n this._parseResponse();\n this._request = null;\n this._response = null;\n this._setReadyState(XMLHttpRequest.DONE);\n this._dispatchProgress('load');\n return this._dispatchProgress('loadend');\n }\n\n // Called when the underlying HTTP connection was closed prematurely.\n\n // If this method is called, it will be called after or instead of\n // onHttpResponseEnd.\n\n // @private\n // @param {http.ClientResponse} response the node.js ClientResponse instance\n // that fired this event\n _onHttpResponseClose(response) {\n var request;\n if (this._response !== response) {\n return;\n }\n request = this._request;\n this._setError();\n request.abort();\n this._setReadyState(XMLHttpRequest.DONE);\n this._dispatchProgress('error');\n return this._dispatchProgress('loadend');\n }\n\n // Called when the timeout set on the HTTP socket expires.\n\n // @private\n // @param {http.ClientRequest} request the node.js ClientRequest instance that\n // fired this event\n _onHttpTimeout(request) {\n if (this._request !== request) {\n return;\n }\n this._setError();\n request.abort();\n this._setReadyState(XMLHttpRequest.DONE);\n this._dispatchProgress('timeout');\n return this._dispatchProgress('loadend');\n }\n\n // Called when something wrong happens on the HTTP socket\n\n // @private\n // @param {http.ClientRequest} request the node.js ClientRequest instance that\n // fired this event\n // @param {Error} error emitted exception\n _onHttpRequestError(request, error) {\n if (this._request !== request) {\n return;\n }\n this._setError();\n request.abort();\n this._setReadyState(XMLHttpRequest.DONE);\n this._dispatchProgress('error');\n return this._dispatchProgress('loadend');\n }\n\n // Fires an XHR progress event.\n\n // @private\n // @param {String} eventType one of the XHR progress event types, such as\n // 'load' and 'progress'\n _dispatchProgress(eventType) {\n var event;\n event = new ProgressEvent(eventType);\n event.lengthComputable = this._lengthComputable;\n event.loaded = this._loadedBytes;\n event.total = this._totalBytes;\n this.dispatchEvent(event);\n return void 0;\n }\n\n // Sets up the XHR to reflect the fact that an error has occurred.\n\n // The possible errors are a network error, a timeout, or an abort.\n\n // @private\n _setError() {\n this._request = null;\n this._response = null;\n this._responseHeaders = null;\n this._responseParts = null;\n return void 0;\n }\n\n // Parses a request URL string.\n\n // @private\n // This method is a thin wrapper around url.parse() that normalizes HTTP\n // user/password credentials. It is used to parse the URL string passed to\n // XMLHttpRequest#open() and the URLs in the Location headers of HTTP redirect\n // responses.\n\n // @param {String} urlString the URL to be parsed\n // @return {Object} parsed URL\n _parseUrl(urlString) {\n var absoluteUrlString, index, password, user, xhrUrl;\n if (this.nodejsBaseUrl === null) {\n absoluteUrlString = urlString;\n } else {\n absoluteUrlString = url.resolve(this.nodejsBaseUrl, urlString);\n }\n xhrUrl = url.parse(absoluteUrlString, false, true);\n xhrUrl.hash = null;\n if (xhrUrl.auth && ((typeof user !== \"undefined\" && user !== null) || (typeof password !== \"undefined\" && password !== null))) {\n index = xhrUrl.auth.indexOf(':');\n if (index === -1) {\n if (!user) {\n user = xhrUrl.auth;\n }\n } else {\n if (!user) {\n user = xhrUrl.substring(0, index);\n }\n if (!password) {\n password = xhrUrl.substring(index + 1);\n }\n }\n }\n if (user || password) {\n xhrUrl.auth = `${user}:${password}`;\n }\n return xhrUrl;\n }\n\n // Reads the headers from a node.js ClientResponse instance.\n\n // @private\n // @param {http.ClientResponse} response the response whose headers will be\n // imported into this XMLHttpRequest's state\n // @return {undefined} undefined\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method\n _parseResponseHeaders(response) {\n var loweredName, name, ref, value;\n this._responseHeaders = {};\n ref = response.headers;\n for (name in ref) {\n value = ref[name];\n loweredName = name.toLowerCase();\n if (this._privateHeaders[loweredName]) {\n continue;\n }\n if (this._mimeOverride !== null && loweredName === 'content-type') {\n value = this._mimeOverride;\n }\n this._responseHeaders[loweredName] = value;\n }\n if (this._mimeOverride !== null && !('content-type' in this._responseHeaders)) {\n this._responseHeaders['content-type'] = this._mimeOverride;\n }\n return void 0;\n }\n\n // Sets the response and responseText properties when an XHR completes.\n\n // @private\n // @return {undefined} undefined\n _parseResponse() {\n var arrayBuffer, buffer, i, j, jsonError, ref, view;\n if (Buffer.concat) {\n buffer = Buffer.concat(this._responseParts);\n } else {\n // node 0.6\n buffer = this._concatBuffers(this._responseParts);\n }\n this._responseParts = null;\n switch (this.responseType) {\n case 'text':\n this._parseTextResponse(buffer);\n break;\n case 'json':\n this.responseText = null;\n try {\n this.response = JSON.parse(buffer.toString('utf-8'));\n } catch (error1) {\n jsonError = error1;\n this.response = null;\n }\n break;\n case 'buffer':\n this.responseText = null;\n this.response = buffer;\n break;\n case 'arraybuffer':\n this.responseText = null;\n arrayBuffer = new ArrayBuffer(buffer.length);\n view = new Uint8Array(arrayBuffer);\n for (i = j = 0, ref = buffer.length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {\n view[i] = buffer[i];\n }\n this.response = arrayBuffer;\n break;\n default:\n // TODO(pwnall): content-base detection\n this._parseTextResponse(buffer);\n }\n return void 0;\n }\n\n // Sets response and responseText for a 'text' response type.\n\n // @private\n // @param {Buffer} buffer the node.js Buffer containing the binary response\n // @return {undefined} undefined\n _parseTextResponse(buffer) {\n var e;\n try {\n this.responseText = buffer.toString(this._parseResponseEncoding());\n } catch (error1) {\n e = error1;\n // Unknown encoding.\n this.responseText = buffer.toString('binary');\n }\n this.response = this.responseText;\n return void 0;\n }\n\n // Figures out the string encoding of the XHR's response.\n\n // This is called to determine the encoding when responseText is set.\n\n // @private\n // @return {String} a string encoding, e.g. 'utf-8'\n _parseResponseEncoding() {\n var contentType, encoding, match;\n encoding = null;\n if (contentType = this._responseHeaders['content-type']) {\n if (match = /\\;\\s*charset\\=(.*)$/.exec(contentType)) {\n return match[1];\n }\n }\n return 'utf-8';\n }\n\n // Buffer.concat implementation for node 0.6.\n\n // @private\n // @param {Array<Buffer>} buffers the buffers whose contents will be merged\n // @return {Buffer} same as Buffer.concat(buffers) in node 0.8 and above\n _concatBuffers(buffers) {\n var buffer, j, k, len, len1, length, target;\n if (buffers.length === 0) {\n return Buffer.alloc(0);\n }\n if (buffers.length === 1) {\n return buffers[0];\n }\n length = 0;\n for (j = 0, len = buffers.length; j < len; j++) {\n buffer = buffers[j];\n length += buffer.length;\n }\n target = Buffer.alloc(length);\n length = 0;\n for (k = 0, len1 = buffers.length; k < len1; k++) {\n buffer = buffers[k];\n buffer.copy(target, length);\n length += buffer.length;\n }\n return target;\n }\n\n };\n\n // @property {function(ProgressEvent)} DOM level 0-style handler for the\n // 'readystatechange' event\n XMLHttpRequest.prototype.onreadystatechange = null;\n\n // @property {Number} the current state of the XHR object\n // @see http://www.w3.org/TR/XMLHttpRequest/#states\n XMLHttpRequest.prototype.readyState = null;\n\n // @property {String, ArrayBuffer, Buffer, Object} processed XHR response\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-response-attribute\n XMLHttpRequest.prototype.response = null;\n\n // @property {String} response string, if responseType is '' or 'text'\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute\n XMLHttpRequest.prototype.responseText = null;\n\n // @property {String} sets the parsing method for the XHR response\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute\n XMLHttpRequest.prototype.responseType = null;\n\n // @property {Number} the HTTP\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-status-attribute\n XMLHttpRequest.prototype.status = null;\n\n // @property {Number} milliseconds to wait for the request to complete\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute\n XMLHttpRequest.prototype.timeout = null;\n\n // @property {XMLHttpRequestUpload} the associated upload information\n // @see http://www.w3.org/TR/XMLHttpRequest/#the-upload-attribute\n XMLHttpRequest.prototype.upload = null;\n\n // readyState value before XMLHttpRequest#open() is called\n XMLHttpRequest.prototype.UNSENT = 0;\n\n // readyState value before XMLHttpRequest#open() is called\n XMLHttpRequest.UNSENT = 0;\n\n // readyState value after XMLHttpRequest#open() is called, and before\n // XMLHttpRequest#send() is called; XMLHttpRequest#setRequestHeader() can be\n // called in this state\n XMLHttpRequest.prototype.OPENED = 1;\n\n // readyState value after XMLHttpRequest#open() is called, and before\n // XMLHttpRequest#send() is called; XMLHttpRequest#setRequestHeader() can be\n // called in this state\n XMLHttpRequest.OPENED = 1;\n\n // readyState value after redirects have been followed and the HTTP headers of\n // the final response have been received\n XMLHttpRequest.prototype.HEADERS_RECEIVED = 2;\n\n // readyState value after redirects have been followed and the HTTP headers of\n // the final response have been received\n XMLHttpRequest.HEADERS_RECEIVED = 2;\n\n // readyState value when the response entity body is being received\n XMLHttpRequest.prototype.LOADING = 3;\n\n // readyState value when the response entity body is being received\n XMLHttpRequest.LOADING = 3;\n\n // readyState value after the request has been completely processed\n XMLHttpRequest.prototype.DONE = 4;\n\n // readyState value after the request has been completely processed\n XMLHttpRequest.DONE = 4;\n\n // @property {http.Agent} the agent option passed to HTTP requests\n\n // NOTE: this is not in the XMLHttpRequest API, and will not work in browsers.\n // It is a stable node-xhr2 API that is useful for testing & going through\n // web-proxies.\n XMLHttpRequest.prototype.nodejsHttpAgent = http.globalAgent;\n\n // @property {https.Agent} the agent option passed to HTTPS requests\n\n // NOTE: this is not in the XMLHttpRequest API, and will not work in browsers.\n // It is a stable node-xhr2 API that is useful for testing & going through\n // web-proxies.\n XMLHttpRequest.prototype.nodejsHttpsAgent = https.globalAgent;\n\n // @property {String} the base URL that relative URLs get resolved to\n\n // NOTE: this is not in the XMLHttpRequest API, and will not work in browsers.\n // Its browser equivalent is the base URL of the document associated with the\n // Window object. It is a stable node-xhr2 API provided for libraries such as\n // Angular Universal.\n XMLHttpRequest.prototype.nodejsBaseUrl = null;\n\n // HTTP methods that are disallowed in the XHR spec.\n\n // @private\n // @see Step 6 in http://www.w3.org/TR/XMLHttpRequest/#the-open()-method\n XMLHttpRequest.prototype._restrictedMethods = {\n CONNECT: true,\n TRACE: true,\n TRACK: true\n };\n\n // HTTP request headers that are disallowed in the XHR spec.\n\n // @private\n // @see Step 5 in\n // http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader()-method\n XMLHttpRequest.prototype._restrictedHeaders = {\n 'accept-charset': true,\n 'accept-encoding': true,\n 'access-control-request-headers': true,\n 'access-control-request-method': true,\n connection: true,\n 'content-length': true,\n cookie: true,\n cookie2: true,\n date: true,\n dnt: true,\n expect: true,\n host: true,\n 'keep-alive': true,\n origin: true,\n referer: true,\n te: true,\n trailer: true,\n 'transfer-encoding': true,\n upgrade: true,\n via: true\n };\n\n // HTTP response headers that should not be exposed according to the XHR spec.\n\n // @private\n // @see Step 3 in\n // http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method\n XMLHttpRequest.prototype._privateHeaders = {\n 'set-cookie': true,\n 'set-cookie2': true\n };\n\n // The default value of the User-Agent header.\n XMLHttpRequest.prototype._userAgent = `Mozilla/5.0 (${os.type()} ${os.arch()}) ` + `node.js/${process.versions.node} v8/${process.versions.v8}`;\n\n return XMLHttpRequest;\n\n }).call(this);\n\n // XMLHttpRequest is the result of require('node-xhr2').\n module.exports = XMLHttpRequest;\n\n // Make node-xhr2 work as a drop-in replacement for libraries that promote the\n // following usage pattern:\n // var XMLHttpRequest = require('xhr-library-name').XMLHttpRequest\n XMLHttpRequest.XMLHttpRequest = XMLHttpRequest;\n\n // This file defines the custom errors used in the XMLHttpRequest specification.\n\n // Thrown if the XHR security policy is violated.\n SecurityError = class SecurityError extends Error {\n // @private\n constructor() {\n super();\n }\n\n };\n\n // Thrown if the XHR security policy is violated.\n XMLHttpRequest.SecurityError = SecurityError;\n\n // Usually thrown if the XHR is in the wrong readyState for an operation.\n InvalidStateError = class InvalidStateError extends Error {\n // @private\n constructor() {\n super();\n }\n\n };\n\n // Usually thrown if the XHR is in the wrong readyState for an operation.\n InvalidStateError = class InvalidStateError extends Error { };\n\n XMLHttpRequest.InvalidStateError = InvalidStateError;\n\n // Thrown if there is a problem with the URL passed to the XHR.\n NetworkError = class NetworkError extends Error {\n // @private\n constructor() {\n super();\n }\n\n };\n\n // Thrown if parsing URLs errors out.\n XMLHttpRequest.SyntaxError = SyntaxError;\n\n SyntaxError = class SyntaxError extends Error {\n // @private:\n constructor() {\n super();\n }\n\n };\n\n ProgressEvent = (function () {\n // http://xhr.spec.whatwg.org/#interface-progressevent\n class ProgressEvent {\n // Creates a new event.\n\n // @param {String} type the event type, e.g. 'readystatechange'; must be\n // lowercased\n constructor(type) {\n this.type = type;\n this.target = null;\n this.currentTarget = null;\n this.lengthComputable = false;\n this.loaded = 0;\n this.total = 0;\n }\n\n };\n\n // Getting the time from the OS is expensive, skip on that for now.\n // @timeStamp = Date.now()\n\n // @property {Boolean} for compatibility with DOM events\n ProgressEvent.prototype.bubbles = false;\n\n // @property {Boolean} for fompatibility with DOM events\n ProgressEvent.prototype.cancelable = false;\n\n // @property {XMLHttpRequest} the request that caused this event\n ProgressEvent.prototype.target = null;\n\n // @property {Number} number of bytes that have already been downloaded or\n // uploaded\n ProgressEvent.prototype.loaded = null;\n\n // @property {Boolean} true if the Content-Length response header is available\n // and the value of the event's total property is meaningful\n ProgressEvent.prototype.lengthComputable = null;\n\n // @property {Number} number of bytes that will be downloaded or uploaded by\n