polling-xhr: obfuscate activex

This commit is contained in:
Guillermo Rauch
2012-10-21 09:48:28 -07:00
parent e1052509da
commit c9445ce647

View File

@@ -4,7 +4,7 @@
var Polling = require('./polling')
, EventEmitter = require('../event-emitter')
, util = require('../util')
, util = require('../util');
/**
* Module exports.
@@ -13,6 +13,12 @@ var Polling = require('./polling')
module.exports = XHR;
module.exports.Request = Request;
/**
* Obfuscated key for Blue Coat.
*/
var xobject = global[['Active'].concat('Object').join('X')];
/**
* Empty function
*/
@@ -30,8 +36,8 @@ function XHR (opts) {
Polling.call(this, opts);
if (global.location) {
this.xd = opts.host != global.location.hostname
|| global.location.port != opts.port;
this.xd = opts.host != global.location.hostname ||
global.location.port != opts.port;
}
};
@@ -77,8 +83,8 @@ XHR.prototype.request = function (opts) {
*/
XHR.prototype.doWrite = function (data, fn) {
var req = this.request({ method: 'POST', data: data })
, self = this
var req = this.request({ method: 'POST', data: data });
var self = this;
req.on('success', fn);
req.on('error', function (err) {
self.onError('xhr post error', err);
@@ -94,8 +100,8 @@ XHR.prototype.doWrite = function (data, fn) {
XHR.prototype.doPoll = function () {
// debug: xhr poll
var req = this.request()
, self = this
var req = this.request();
var self = this;
req.on('data', function (data) {
self.onData(data);
});
@@ -134,8 +140,8 @@ util.inherits(Request, EventEmitter);
*/
Request.prototype.create = function () {
var xhr = this.xhr = util.request(this.xd)
, self = this
var xhr = this.xhr = util.request(this.xd);
var self = this;
xhr.open(this.method, this.uri, this.async);
@@ -188,7 +194,7 @@ Request.prototype.create = function () {
// debug: sending xhr with url %s | data %s, this.uri, this.data
xhr.send(this.data);
if (global.ActiveXObject) {
if (xobject) {
this.index = Request.requestsCount++;
Request.requests[this.index] = this;
}
@@ -203,7 +209,7 @@ Request.prototype.create = function () {
Request.prototype.onSuccess = function () {
this.emit('success');
this.cleanup();
}
};
/**
* Called if we have data.
@@ -214,7 +220,7 @@ Request.prototype.onSuccess = function () {
Request.prototype.onData = function (data) {
this.emit('data', data);
this.onSuccess();
}
};
/**
* Called upon error.
@@ -225,7 +231,7 @@ Request.prototype.onData = function (data) {
Request.prototype.onError = function (err) {
this.emit('error', err);
this.cleanup();
}
};
/**
* Cleans up house.
@@ -244,12 +250,12 @@ Request.prototype.cleanup = function () {
this.xhr.abort();
} catch(e) {}
if (global.ActiveXObject) {
if (xobject) {
delete Request.requests[this.index];
}
this.xhr = null;
}
};
/**
* Aborts the request.
@@ -261,7 +267,7 @@ Request.prototype.abort = function () {
this.cleanup();
};
if (global.ActiveXObject) {
if (xobject) {
Request.requestsCount = 0;
Request.requests = {};