-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
53 lines (41 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// XMLHttpRequest to override.
var xhrPath = '../socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest';
//Require it for the first time to store it in the require.cache
require(xhrPath);
//Get the resolved filename which happens to be the key of the module in the cache object
var xhrName = require.resolve(xhrPath);
//Get the cached xhr module
var cachedXhr = require.cache[xhrName].exports;
//Cookies to be applied in the xhr
var cookies;
////Monkey Patch
var newXhr = function () {
cachedXhr.apply(this, arguments);
this.setDisableHeaderCheck(true);
var stdOpen = this.open;
this.open = function () {
stdOpen.apply(this, arguments);
this.setRequestHeader('Cookie', cookies);
}
};
newXhr.XMLHttpRequest = newXhr;
require.cache[xhrName].exports = newXhr;
module.exports = newXhr;
module.exports.setCookies = function(newCookies) {
cookies = newCookies;
};
//Monkey patch that allows to add custom functions before calling socket.io constructor
//// Example
//callbacks.test = function () {
// console.log("In callback.");
//};
//
////Monkey Patch
//var newXhr = function () {
// cachedXhr.apply(this, arguments);
// for (var method in callbacks) {
// if (typeof callbacks[method] == "function") {
// callbacks[method].apply(this, arguments);
// }
// }
//};