| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874 |
- // Generated by CoffeeScript 1.9.3
- (function() {
- var InvalidStateError, NetworkError, ProgressEvent, SecurityError, SyntaxError, XMLHttpRequest, XMLHttpRequestEventTarget, XMLHttpRequestUpload, http, https, os, url,
- extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
- hasProp = {}.hasOwnProperty;
-
- XMLHttpRequestEventTarget = (function() {
- function XMLHttpRequestEventTarget() {
- this.onloadstart = null;
- this.onprogress = null;
- this.onabort = null;
- this.onerror = null;
- this.onload = null;
- this.ontimeout = null;
- this.onloadend = null;
- this._listeners = {};
- }
-
- XMLHttpRequestEventTarget.prototype.onloadstart = null;
-
- XMLHttpRequestEventTarget.prototype.onprogress = null;
-
- XMLHttpRequestEventTarget.prototype.onabort = null;
-
- XMLHttpRequestEventTarget.prototype.onerror = null;
-
- XMLHttpRequestEventTarget.prototype.onload = null;
-
- XMLHttpRequestEventTarget.prototype.ontimeout = null;
-
- XMLHttpRequestEventTarget.prototype.onloadend = null;
-
- XMLHttpRequestEventTarget.prototype.addEventListener = function(eventType, listener) {
- var base;
- eventType = eventType.toLowerCase();
- (base = this._listeners)[eventType] || (base[eventType] = []);
- this._listeners[eventType].push(listener);
- return void 0;
- };
-
- XMLHttpRequestEventTarget.prototype.removeEventListener = function(eventType, listener) {
- var index;
- eventType = eventType.toLowerCase();
- if (this._listeners[eventType]) {
- index = this._listeners[eventType].indexOf(listener);
- if (index !== -1) {
- this._listeners[eventType].splice(index, 1);
- }
- }
- return void 0;
- };
-
- XMLHttpRequestEventTarget.prototype.dispatchEvent = function(event) {
- var eventType, j, len, listener, listeners;
- event.currentTarget = event.target = this;
- eventType = event.type;
- if (listeners = this._listeners[eventType]) {
- for (j = 0, len = listeners.length; j < len; j++) {
- listener = listeners[j];
- listener.call(this, event);
- }
- }
- if (listener = this["on" + eventType]) {
- listener.call(this, event);
- }
- return void 0;
- };
-
- return XMLHttpRequestEventTarget;
-
- })();
-
- http = require('http');
-
- https = require('https');
-
- os = require('os');
-
- url = require('url');
-
- XMLHttpRequest = (function(superClass) {
- extend(XMLHttpRequest, superClass);
-
- function XMLHttpRequest(options) {
- XMLHttpRequest.__super__.constructor.call(this);
- this.onreadystatechange = null;
- this._anonymous = options && options.anon;
- this.readyState = XMLHttpRequest.UNSENT;
- this.response = null;
- this.responseText = '';
- this.responseType = '';
- this.status = 0;
- this.statusText = '';
- this.timeout = 0;
- this.upload = new XMLHttpRequestUpload(this);
- this._method = null;
- this._url = null;
- this._sync = false;
- this._headers = null;
- this._loweredHeaders = null;
- this._mimeOverride = null;
- this._request = null;
- this._response = null;
- this._responseParts = null;
- this._responseHeaders = null;
- this._aborting = null;
- this._error = null;
- this._loadedBytes = 0;
- this._totalBytes = 0;
- this._lengthComputable = false;
- }
-
- XMLHttpRequest.prototype.onreadystatechange = null;
-
- XMLHttpRequest.prototype.readyState = null;
-
- XMLHttpRequest.prototype.response = null;
-
- XMLHttpRequest.prototype.responseText = null;
-
- XMLHttpRequest.prototype.responseType = null;
-
- XMLHttpRequest.prototype.status = null;
-
- XMLHttpRequest.prototype.timeout = null;
-
- XMLHttpRequest.prototype.upload = null;
-
- XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
- var xhrUrl;
- method = method.toUpperCase();
- if (method in this._restrictedMethods) {
- throw new SecurityError("HTTP method " + method + " is not allowed in XHR");
- }
- xhrUrl = this._parseUrl(url);
- if (async === void 0) {
- async = true;
- }
- switch (this.readyState) {
- case XMLHttpRequest.UNSENT:
- case XMLHttpRequest.OPENED:
- case XMLHttpRequest.DONE:
- null;
- break;
- case XMLHttpRequest.HEADERS_RECEIVED:
- case XMLHttpRequest.LOADING:
- null;
- }
- this._method = method;
- this._url = xhrUrl;
- this._sync = !async;
- this._headers = {};
- this._loweredHeaders = {};
- this._mimeOverride = null;
- this._setReadyState(XMLHttpRequest.OPENED);
- this._request = null;
- this._response = null;
- this.status = 0;
- this.statusText = '';
- this._responseParts = [];
- this._responseHeaders = null;
- this._loadedBytes = 0;
- this._totalBytes = 0;
- this._lengthComputable = false;
- return void 0;
- };
-
- XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
- var loweredName;
- if (this.readyState !== XMLHttpRequest.OPENED) {
- throw new InvalidStateError("XHR readyState must be OPENED");
- }
- loweredName = name.toLowerCase();
- if (this._restrictedHeaders[loweredName] || /^sec\-/.test(loweredName) || /^proxy-/.test(loweredName)) {
- console.warn("Refused to set unsafe header \"" + name + "\"");
- return void 0;
- }
- value = value.toString();
- if (loweredName in this._loweredHeaders) {
- name = this._loweredHeaders[loweredName];
- this._headers[name] = this._headers[name] + ', ' + value;
- } else {
- this._loweredHeaders[loweredName] = name;
- this._headers[name] = value;
- }
- return void 0;
- };
-
- XMLHttpRequest.prototype.send = function(data) {
- if (this.readyState !== XMLHttpRequest.OPENED) {
- throw new InvalidStateError("XHR readyState must be OPENED");
- }
- if (this._request) {
- throw new InvalidStateError("send() already called");
- }
- switch (this._url.protocol) {
- case 'file:':
- this._sendFile(data);
- break;
- case 'http:':
- case 'https:':
- this._sendHttp(data);
- break;
- default:
- throw new NetworkError("Unsupported protocol " + this._url.protocol);
- }
- return void 0;
- };
-
- XMLHttpRequest.prototype.abort = function() {
- if (!this._request) {
- return;
- }
- this._request.abort();
- this._setError();
- this._dispatchProgress('abort');
- this._dispatchProgress('loadend');
- return void 0;
- };
-
- XMLHttpRequest.prototype.getResponseHeader = function(name) {
- var loweredName;
- if (!this._responseHeaders) {
- return null;
- }
- loweredName = name.toLowerCase();
- if (loweredName in this._responseHeaders) {
- return this._responseHeaders[loweredName];
- } else {
- return null;
- }
- };
-
- XMLHttpRequest.prototype.getAllResponseHeaders = function() {
- var lines, name, value;
- if (!this._responseHeaders) {
- return '';
- }
- lines = (function() {
- var ref, results;
- ref = this._responseHeaders;
- results = [];
- for (name in ref) {
- value = ref[name];
- results.push(name + ": " + value);
- }
- return results;
- }).call(this);
- return lines.join("\r\n");
- };
-
- XMLHttpRequest.prototype.overrideMimeType = function(newMimeType) {
- if (this.readyState === XMLHttpRequest.LOADING || this.readyState === XMLHttpRequest.DONE) {
- throw new InvalidStateError("overrideMimeType() not allowed in LOADING or DONE");
- }
- this._mimeOverride = newMimeType.toLowerCase();
- return void 0;
- };
-
- XMLHttpRequest.prototype.nodejsSet = function(options) {
- var baseUrl, parsedUrl;
- if ('httpAgent' in options) {
- this.nodejsHttpAgent = options.httpAgent;
- }
- if ('httpsAgent' in options) {
- this.nodejsHttpsAgent = options.httpsAgent;
- }
- if ('baseUrl' in options) {
- baseUrl = options.baseUrl;
- if (baseUrl !== null) {
- parsedUrl = url.parse(baseUrl, false, true);
- if (!parsedUrl.protocol) {
- throw new SyntaxError("baseUrl must be an absolute URL");
- }
- }
- this.nodejsBaseUrl = baseUrl;
- }
- return void 0;
- };
-
- XMLHttpRequest.nodejsSet = function(options) {
- XMLHttpRequest.prototype.nodejsSet(options);
- return void 0;
- };
-
- XMLHttpRequest.prototype.UNSENT = 0;
-
- XMLHttpRequest.UNSENT = 0;
-
- XMLHttpRequest.prototype.OPENED = 1;
-
- XMLHttpRequest.OPENED = 1;
-
- XMLHttpRequest.prototype.HEADERS_RECEIVED = 2;
-
- XMLHttpRequest.HEADERS_RECEIVED = 2;
-
- XMLHttpRequest.prototype.LOADING = 3;
-
- XMLHttpRequest.LOADING = 3;
-
- XMLHttpRequest.prototype.DONE = 4;
-
- XMLHttpRequest.DONE = 4;
-
- XMLHttpRequest.prototype.nodejsHttpAgent = http.globalAgent;
-
- XMLHttpRequest.prototype.nodejsHttpsAgent = https.globalAgent;
-
- XMLHttpRequest.prototype.nodejsBaseUrl = null;
-
- XMLHttpRequest.prototype._restrictedMethods = {
- CONNECT: true,
- TRACE: true,
- TRACK: true
- };
-
- XMLHttpRequest.prototype._restrictedHeaders = {
- 'accept-charset': true,
- 'accept-encoding': true,
- 'access-control-request-headers': true,
- 'access-control-request-method': true,
- connection: true,
- 'content-length': true,
- cookie: true,
- cookie2: true,
- date: true,
- dnt: true,
- expect: true,
- host: true,
- 'keep-alive': true,
- origin: true,
- referer: true,
- te: true,
- trailer: true,
- 'transfer-encoding': true,
- upgrade: true,
- 'user-agent': true,
- via: true
- };
-
- XMLHttpRequest.prototype._privateHeaders = {
- 'set-cookie': true,
- 'set-cookie2': true
- };
-
- XMLHttpRequest.prototype._userAgent = ("Mozilla/5.0 (" + (os.type()) + " " + (os.arch()) + ") ") + ("node.js/" + process.versions.node + " v8/" + process.versions.v8);
-
- XMLHttpRequest.prototype._setReadyState = function(newReadyState) {
- var event;
- this.readyState = newReadyState;
- event = new ProgressEvent('readystatechange');
- this.dispatchEvent(event);
- return void 0;
- };
-
- XMLHttpRequest.prototype._sendFile = function() {
- if (this._url.method !== 'GET') {
- throw new NetworkError('The file protocol only supports GET');
- }
- throw new Error("Protocol file: not implemented");
- };
-
- XMLHttpRequest.prototype._sendHttp = function(data) {
- if (this._sync) {
- throw new Error("Synchronous XHR processing not implemented");
- }
- if ((data != null) && (this._method === 'GET' || this._method === 'HEAD')) {
- console.warn("Discarding entity body for " + this._method + " requests");
- data = null;
- } else {
- data || (data = '');
- }
- this.upload._setData(data);
- this._finalizeHeaders();
- this._sendHxxpRequest();
- return void 0;
- };
-
- XMLHttpRequest.prototype._sendHxxpRequest = function() {
- var agent, hxxp, request;
- if (this._url.protocol === 'http:') {
- hxxp = http;
- agent = this.nodejsHttpAgent;
- } else {
- hxxp = https;
- agent = this.nodejsHttpsAgent;
- }
- request = hxxp.request({
- hostname: this._url.hostname,
- port: this._url.port,
- path: this._url.path,
- auth: this._url.auth,
- method: this._method,
- headers: this._headers,
- agent: agent
- });
- this._request = request;
- if (this.timeout) {
- request.setTimeout(this.timeout, (function(_this) {
- return function() {
- return _this._onHttpTimeout(request);
- };
- })(this));
- }
- request.on('response', (function(_this) {
- return function(response) {
- return _this._onHttpResponse(request, response);
- };
- })(this));
- request.on('error', (function(_this) {
- return function(error) {
- return _this._onHttpRequestError(request, error);
- };
- })(this));
- this.upload._startUpload(request);
- if (this._request === request) {
- this._dispatchProgress('loadstart');
- }
- return void 0;
- };
-
- XMLHttpRequest.prototype._finalizeHeaders = function() {
- this._headers['Connection'] = 'keep-alive';
- this._headers['Host'] = this._url.host;
- if (this._anonymous) {
- this._headers['Referer'] = 'about:blank';
- }
- this._headers['User-Agent'] = this._userAgent;
- this.upload._finalizeHeaders(this._headers, this._loweredHeaders);
- return void 0;
- };
-
- XMLHttpRequest.prototype._onHttpResponse = function(request, response) {
- var lengthString;
- if (this._request !== request) {
- return;
- }
- switch (response.statusCode) {
- case 301:
- case 302:
- case 303:
- case 307:
- case 308:
- this._url = this._parseUrl(response.headers['location']);
- this._method = 'GET';
- if ('content-type' in this._loweredHeaders) {
- delete this._headers[this._loweredHeaders['content-type']];
- delete this._loweredHeaders['content-type'];
- }
- if ('Content-Type' in this._headers) {
- delete this._headers['Content-Type'];
- }
- delete this._headers['Content-Length'];
- this.upload._reset();
- this._finalizeHeaders();
- this._sendHxxpRequest();
- return;
- }
- this._response = response;
- this._response.on('data', (function(_this) {
- return function(data) {
- return _this._onHttpResponseData(response, data);
- };
- })(this));
- this._response.on('end', (function(_this) {
- return function() {
- return _this._onHttpResponseEnd(response);
- };
- })(this));
- this._response.on('close', (function(_this) {
- return function() {
- return _this._onHttpResponseClose(response);
- };
- })(this));
- this.status = this._response.statusCode;
- this.statusText = http.STATUS_CODES[this.status];
- this._parseResponseHeaders(response);
- if (lengthString = this._responseHeaders['content-length']) {
- this._totalBytes = parseInt(lengthString);
- this._lengthComputable = true;
- } else {
- this._lengthComputable = false;
- }
- return this._setReadyState(XMLHttpRequest.HEADERS_RECEIVED);
- };
-
- XMLHttpRequest.prototype._onHttpResponseData = function(response, data) {
- if (this._response !== response) {
- return;
- }
- this._responseParts.push(data);
- this._loadedBytes += data.length;
- if (this.readyState !== XMLHttpRequest.LOADING) {
- this._setReadyState(XMLHttpRequest.LOADING);
- }
- return this._dispatchProgress('progress');
- };
-
- XMLHttpRequest.prototype._onHttpResponseEnd = function(response) {
- if (this._response !== response) {
- return;
- }
- this._parseResponse();
- this._request = null;
- this._response = null;
- this._setReadyState(XMLHttpRequest.DONE);
- this._dispatchProgress('load');
- return this._dispatchProgress('loadend');
- };
-
- XMLHttpRequest.prototype._onHttpResponseClose = function(response) {
- var request;
- if (this._response !== response) {
- return;
- }
- request = this._request;
- this._setError();
- request.abort();
- this._setReadyState(XMLHttpRequest.DONE);
- this._dispatchProgress('error');
- return this._dispatchProgress('loadend');
- };
-
- XMLHttpRequest.prototype._onHttpTimeout = function(request) {
- if (this._request !== request) {
- return;
- }
- this._setError();
- request.abort();
- this._setReadyState(XMLHttpRequest.DONE);
- this._dispatchProgress('timeout');
- return this._dispatchProgress('loadend');
- };
-
- XMLHttpRequest.prototype._onHttpRequestError = function(request, error) {
- if (this._request !== request) {
- return;
- }
- this._setError();
- request.abort();
- this._setReadyState(XMLHttpRequest.DONE);
- this._dispatchProgress('error');
- return this._dispatchProgress('loadend');
- };
-
- XMLHttpRequest.prototype._dispatchProgress = function(eventType) {
- var event;
- event = new ProgressEvent(eventType);
- event.lengthComputable = this._lengthComputable;
- event.loaded = this._loadedBytes;
- event.total = this._totalBytes;
- this.dispatchEvent(event);
- return void 0;
- };
-
- XMLHttpRequest.prototype._setError = function() {
- this._request = null;
- this._response = null;
- this._responseHeaders = null;
- this._responseParts = null;
- return void 0;
- };
-
- XMLHttpRequest.prototype._parseUrl = function(urlString) {
- var absoluteUrlString, index, password, user, xhrUrl;
- if (this.nodejsBaseUrl === null) {
- absoluteUrlString = urlString;
- } else {
- absoluteUrlString = url.resolve(this.nodejsBaseUrl, urlString);
- }
- xhrUrl = url.parse(absoluteUrlString, false, true);
- xhrUrl.hash = null;
- if (xhrUrl.auth && ((typeof user !== "undefined" && user !== null) || (typeof password !== "undefined" && password !== null))) {
- index = xhrUrl.auth.indexOf(':');
- if (index === -1) {
- if (!user) {
- user = xhrUrl.auth;
- }
- } else {
- if (!user) {
- user = xhrUrl.substring(0, index);
- }
- if (!password) {
- password = xhrUrl.substring(index + 1);
- }
- }
- }
- if (user || password) {
- xhrUrl.auth = user + ":" + password;
- }
- return xhrUrl;
- };
-
- XMLHttpRequest.prototype._parseResponseHeaders = function(response) {
- var loweredName, name, ref, value;
- this._responseHeaders = {};
- ref = response.headers;
- for (name in ref) {
- value = ref[name];
- loweredName = name.toLowerCase();
- if (this._privateHeaders[loweredName]) {
- continue;
- }
- if (this._mimeOverride !== null && loweredName === 'content-type') {
- value = this._mimeOverride;
- }
- this._responseHeaders[loweredName] = value;
- }
- if (this._mimeOverride !== null && !('content-type' in this._responseHeaders)) {
- this._responseHeaders['content-type'] = this._mimeOverride;
- }
- return void 0;
- };
-
- XMLHttpRequest.prototype._parseResponse = function() {
- var arrayBuffer, buffer, i, j, jsonError, ref, view;
- if (Buffer.concat) {
- buffer = Buffer.concat(this._responseParts);
- } else {
- buffer = this._concatBuffers(this._responseParts);
- }
- this._responseParts = null;
- switch (this.responseType) {
- case 'text':
- this._parseTextResponse(buffer);
- break;
- case 'json':
- this.responseText = null;
- try {
- this.response = JSON.parse(buffer.toString('utf-8'));
- } catch (_error) {
- jsonError = _error;
- this.response = null;
- }
- break;
- case 'buffer':
- this.responseText = null;
- this.response = buffer;
- break;
- case 'arraybuffer':
- this.responseText = null;
- arrayBuffer = new ArrayBuffer(buffer.length);
- view = new Uint8Array(arrayBuffer);
- for (i = j = 0, ref = buffer.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
- view[i] = buffer[i];
- }
- this.response = arrayBuffer;
- break;
- default:
- this._parseTextResponse(buffer);
- }
- return void 0;
- };
-
- XMLHttpRequest.prototype._parseTextResponse = function(buffer) {
- var e;
- try {
- this.responseText = buffer.toString(this._parseResponseEncoding());
- } catch (_error) {
- e = _error;
- this.responseText = buffer.toString('binary');
- }
- this.response = this.responseText;
- return void 0;
- };
-
- XMLHttpRequest.prototype._parseResponseEncoding = function() {
- var contentType, encoding, match;
- encoding = null;
- if (contentType = this._responseHeaders['content-type']) {
- if (match = /\;\s*charset\=(.*)$/.exec(contentType)) {
- return match[1];
- }
- }
- return 'utf-8';
- };
-
- XMLHttpRequest.prototype._concatBuffers = function(buffers) {
- var buffer, j, k, len, len1, length, target;
- if (buffers.length === 0) {
- return new Buffer(0);
- }
- if (buffers.length === 1) {
- return buffers[0];
- }
- length = 0;
- for (j = 0, len = buffers.length; j < len; j++) {
- buffer = buffers[j];
- length += buffer.length;
- }
- target = new Buffer(length);
- length = 0;
- for (k = 0, len1 = buffers.length; k < len1; k++) {
- buffer = buffers[k];
- buffer.copy(target, length);
- length += buffer.length;
- }
- return target;
- };
-
- return XMLHttpRequest;
-
- })(XMLHttpRequestEventTarget);
-
- module.exports = XMLHttpRequest;
-
- XMLHttpRequest.XMLHttpRequest = XMLHttpRequest;
-
- SecurityError = (function(superClass) {
- extend(SecurityError, superClass);
-
- function SecurityError() {
- SecurityError.__super__.constructor.apply(this, arguments);
- }
-
- return SecurityError;
-
- })(Error);
-
- XMLHttpRequest.SecurityError = SecurityError;
-
- InvalidStateError = (function(superClass) {
- extend(InvalidStateError, superClass);
-
- function InvalidStateError() {
- InvalidStateError.__super__.constructor.apply(this, arguments);
- }
-
- return InvalidStateError;
-
- })(Error);
-
- InvalidStateError = (function(superClass) {
- extend(InvalidStateError, superClass);
-
- function InvalidStateError() {
- return InvalidStateError.__super__.constructor.apply(this, arguments);
- }
-
- return InvalidStateError;
-
- })(Error);
-
- XMLHttpRequest.InvalidStateError = InvalidStateError;
-
- NetworkError = (function(superClass) {
- extend(NetworkError, superClass);
-
- function NetworkError() {
- NetworkError.__super__.constructor.apply(this, arguments);
- }
-
- return NetworkError;
-
- })(Error);
-
- XMLHttpRequest.SyntaxError = SyntaxError;
-
- SyntaxError = (function(superClass) {
- extend(SyntaxError, superClass);
-
- function SyntaxError() {
- SyntaxError.__super__.constructor.apply(this, arguments);
- }
-
- return SyntaxError;
-
- })(Error);
-
- ProgressEvent = (function() {
- function ProgressEvent(type) {
- this.type = type;
- this.target = null;
- this.currentTarget = null;
- this.lengthComputable = false;
- this.loaded = 0;
- this.total = 0;
- }
-
- ProgressEvent.prototype.bubbles = false;
-
- ProgressEvent.prototype.cancelable = false;
-
- ProgressEvent.prototype.target = null;
-
- ProgressEvent.prototype.loaded = null;
-
- ProgressEvent.prototype.lengthComputable = null;
-
- ProgressEvent.prototype.total = null;
-
- return ProgressEvent;
-
- })();
-
- XMLHttpRequest.ProgressEvent = ProgressEvent;
-
- XMLHttpRequestUpload = (function(superClass) {
- extend(XMLHttpRequestUpload, superClass);
-
- function XMLHttpRequestUpload(request) {
- XMLHttpRequestUpload.__super__.constructor.call(this);
- this._request = request;
- this._reset();
- }
-
- XMLHttpRequestUpload.prototype._reset = function() {
- this._contentType = null;
- this._body = null;
- return void 0;
- };
-
- XMLHttpRequestUpload.prototype._setData = function(data) {
- var body, i, j, k, offset, ref, ref1, view;
- if (typeof data === 'undefined' || data === null) {
- return;
- }
- if (typeof data === 'string') {
- if (data.length !== 0) {
- this._contentType = 'text/plain;charset=UTF-8';
- }
- this._body = new Buffer(data, 'utf8');
- } else if (Buffer.isBuffer(data)) {
- this._body = data;
- } else if (data instanceof ArrayBuffer) {
- body = new Buffer(data.byteLength);
- view = new Uint8Array(data);
- for (i = j = 0, ref = data.byteLength; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
- body[i] = view[i];
- }
- this._body = body;
- } else if (data.buffer && data.buffer instanceof ArrayBuffer) {
- body = new Buffer(data.byteLength);
- offset = data.byteOffset;
- view = new Uint8Array(data.buffer);
- for (i = k = 0, ref1 = data.byteLength; 0 <= ref1 ? k < ref1 : k > ref1; i = 0 <= ref1 ? ++k : --k) {
- body[i] = view[i + offset];
- }
- this._body = body;
- } else {
- throw new Error("Unsupported send() data " + data);
- }
- return void 0;
- };
-
- XMLHttpRequestUpload.prototype._finalizeHeaders = function(headers, loweredHeaders) {
- if (this._contentType) {
- if (!('content-type' in loweredHeaders)) {
- headers['Content-Type'] = this._contentType;
- }
- }
- if (this._body) {
- headers['Content-Length'] = this._body.length.toString();
- }
- return void 0;
- };
-
- XMLHttpRequestUpload.prototype._startUpload = function(request) {
- if (this._body) {
- request.write(this._body);
- }
- request.end();
- return void 0;
- };
-
- return XMLHttpRequestUpload;
-
- })(XMLHttpRequestEventTarget);
-
- XMLHttpRequest.XMLHttpRequestUpload = XMLHttpRequestUpload;
-
- }).call(this);
|