davechri 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of davechri might be problematic. Click here for more details.
- package/README.md +277 -0
- package/bin/proxyall +5 -0
- package/build/app.js +89 -0
- package/build/app.js.map +1 -0
- package/build/common/Message.js +34 -0
- package/build/common/Message.js.map +1 -0
- package/build/common/ProxyConfig.js +27 -0
- package/build/common/ProxyConfig.js.map +1 -0
- package/build/node-http-mitm-proxy/.gitattributes +2 -0
- package/build/node-http-mitm-proxy/.travis.yml +10 -0
- package/build/node-http-mitm-proxy/README.md +539 -0
- package/build/node-http-mitm-proxy/bin/mitm-proxy.js +36 -0
- package/build/node-http-mitm-proxy/examples/forwardHttps.js +62 -0
- package/build/node-http-mitm-proxy/examples/modifyGoogle.js +44 -0
- package/build/node-http-mitm-proxy/examples/onCertificateMissing.js +30 -0
- package/build/node-http-mitm-proxy/examples/onCertificateRequired.js +23 -0
- package/build/node-http-mitm-proxy/examples/preventRequest.js +20 -0
- package/build/node-http-mitm-proxy/examples/processFullResponseBody.js +36 -0
- package/build/node-http-mitm-proxy/examples/removeProxyToServerContentLength.js +17 -0
- package/build/node-http-mitm-proxy/examples/websocket.js +31 -0
- package/build/node-http-mitm-proxy/examples/wildcard.js +17 -0
- package/build/node-http-mitm-proxy/index.d.ts +233 -0
- package/build/node-http-mitm-proxy/index.js +3 -0
- package/build/node-http-mitm-proxy/lib/ca.js +245 -0
- package/build/node-http-mitm-proxy/lib/middleware/gunzip.js +19 -0
- package/build/node-http-mitm-proxy/lib/middleware/wildcard.js +22 -0
- package/build/node-http-mitm-proxy/lib/proxy.js +1137 -0
- package/build/node-http-mitm-proxy/package-lock.json +1406 -0
- package/build/node-http-mitm-proxy/package.json +45 -0
- package/build/node-http-mitm-proxy/test/01_proxy.js +449 -0
- package/build/node-http-mitm-proxy/test/www/1024.bin +64 -0
- package/build/node-http-mitm-proxy/test/wwwA/1024.bin +64 -0
- package/build/node-http-mitm-proxy/test/wwwA/example.com.html +8 -0
- package/build/node-http-mitm-proxy/test/wwwA/index.html +0 -0
- package/build/node-http-mitm-proxy/test/wwwB/1024.bin +64 -0
- package/build/node-http-mitm-proxy/test/wwwB/index.html +0 -0
- package/build/private/keys/README.md +2 -0
- package/build/private/keys/server.crt +20 -0
- package/build/private/keys/server.key +28 -0
- package/build/private/keys/ssl.conf +25 -0
- package/build/server/src/Global.js +38 -0
- package/build/server/src/Global.js.map +1 -0
- package/build/server/src/Http2Proxy.js +197 -0
- package/build/server/src/Http2Proxy.js.map +1 -0
- package/build/server/src/HttpMessage.js +99 -0
- package/build/server/src/HttpMessage.js.map +1 -0
- package/build/server/src/HttpProxy.js +196 -0
- package/build/server/src/HttpProxy.js.map +1 -0
- package/build/server/src/HttpsProxy.js +110 -0
- package/build/server/src/HttpsProxy.js.map +1 -0
- package/build/server/src/LogProxy.js +115 -0
- package/build/server/src/LogProxy.js.map +1 -0
- package/build/server/src/Paths.js +28 -0
- package/build/server/src/Paths.js.map +1 -0
- package/build/server/src/Ping.js +21 -0
- package/build/server/src/Ping.js.map +1 -0
- package/build/server/src/ProxyAllApp.js +70 -0
- package/build/server/src/ProxyAllApp.js.map +1 -0
- package/build/server/src/Resend.js +89 -0
- package/build/server/src/Resend.js.map +1 -0
- package/build/server/src/SocketIoManager.js +312 -0
- package/build/server/src/SocketIoManager.js.map +1 -0
- package/build/server/src/SocketMessage.js +68 -0
- package/build/server/src/SocketMessage.js.map +1 -0
- package/build/server/src/TcpProxy.js +202 -0
- package/build/server/src/TcpProxy.js.map +1 -0
- package/build/server/src/formatters/HexFormatter.js +33 -0
- package/build/server/src/formatters/HexFormatter.js.map +1 -0
- package/build/server/src/formatters/MongoFormatter.js +97 -0
- package/build/server/src/formatters/MongoFormatter.js.map +1 -0
- package/build/server/src/formatters/MongoOpCode.js +51 -0
- package/build/server/src/formatters/MongoOpCode.js.map +1 -0
- package/build/server/src/formatters/RedisFormatter.js +25 -0
- package/build/server/src/formatters/RedisFormatter.js.map +1 -0
- package/build/server/src/formatters/SqlCommand.js +111 -0
- package/build/server/src/formatters/SqlCommand.js.map +1 -0
- package/build/server/src/formatters/SqlFormatter.js +150 -0
- package/build/server/src/formatters/SqlFormatter.js.map +1 -0
- package/client/README.md +46 -0
- package/client/build/asset-manifest.json +26 -0
- package/client/build/favicon.ico +0 -0
- package/client/build/index.html +1 -0
- package/client/build/manifest.json +8 -0
- package/client/build/robots.txt +3 -0
- package/client/build/static/css/2.bbde182e.chunk.css +12 -0
- package/client/build/static/css/2.bbde182e.chunk.css.map +1 -0
- package/client/build/static/css/main.5bf489b2.chunk.css +2 -0
- package/client/build/static/css/main.5bf489b2.chunk.css.map +1 -0
- package/client/build/static/js/2.ba308ba1.chunk.js +3 -0
- package/client/build/static/js/2.ba308ba1.chunk.js.LICENSE.txt +100 -0
- package/client/build/static/js/2.ba308ba1.chunk.js.map +1 -0
- package/client/build/static/js/3.7073b0d8.chunk.js +2 -0
- package/client/build/static/js/3.7073b0d8.chunk.js.map +1 -0
- package/client/build/static/js/main.494a7501.chunk.js +2 -0
- package/client/build/static/js/main.494a7501.chunk.js.map +1 -0
- package/client/build/static/js/runtime-main.00264969.js +2 -0
- package/client/build/static/js/runtime-main.00264969.js.map +1 -0
- package/client/build/static/media/fa-brands-400.2285773e.woff +0 -0
- package/client/build/static/media/fa-brands-400.23f19bb0.eot +0 -0
- package/client/build/static/media/fa-brands-400.2f517e09.svg +3717 -0
- package/client/build/static/media/fa-brands-400.527940b1.ttf +0 -0
- package/client/build/static/media/fa-brands-400.d878b0a6.woff2 +0 -0
- package/client/build/static/media/fa-regular-400.4689f52c.svg +801 -0
- package/client/build/static/media/fa-regular-400.491974d1.ttf +0 -0
- package/client/build/static/media/fa-regular-400.77206a6b.eot +0 -0
- package/client/build/static/media/fa-regular-400.7a333762.woff2 +0 -0
- package/client/build/static/media/fa-regular-400.bb58e57c.woff +0 -0
- package/client/build/static/media/fa-solid-900.1551f4f6.woff2 +0 -0
- package/client/build/static/media/fa-solid-900.7a8b4f13.svg +5034 -0
- package/client/build/static/media/fa-solid-900.9bbb245e.eot +0 -0
- package/client/build/static/media/fa-solid-900.be9ee23c.ttf +0 -0
- package/client/build/static/media/fa-solid-900.eeccf4f6.woff +0 -0
- package/package.json +80 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "http-mitm-proxy",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "HTTP Man In The Middle (MITM) Proxy",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "mocha"
|
|
9
|
+
},
|
|
10
|
+
"repository": "https://github.com/joeferner/node-http-mitm-proxy",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/joeferner/node-http-mitm-proxy/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"http-mitm-proxy": "./bin/mitm-proxy.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mitm",
|
|
19
|
+
"http",
|
|
20
|
+
"https",
|
|
21
|
+
"ssl",
|
|
22
|
+
"websocket",
|
|
23
|
+
"proxy"
|
|
24
|
+
],
|
|
25
|
+
"author": "Joe Ferner <joe@fernsroth.com>",
|
|
26
|
+
"contributors": [
|
|
27
|
+
"Félicien François <felicien@tweakstyle.com>",
|
|
28
|
+
"Simon Pratt <simon@pr4tt.com>"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"mocha": "^8.2.0",
|
|
33
|
+
"node-static": "^0.7.10",
|
|
34
|
+
"request": "^2.83.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"async": "^3.2.0",
|
|
38
|
+
"debug": "^4.1.0",
|
|
39
|
+
"mkdirp": "^0.5.1",
|
|
40
|
+
"node-forge": "^0.10.0",
|
|
41
|
+
"semaphore": "^1.1.0",
|
|
42
|
+
"ws": "^5.2.3",
|
|
43
|
+
"yargs": "^16.1.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
var util = require('util');
|
|
2
|
+
var assert = require('assert');
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
var zlib = require('zlib');
|
|
5
|
+
var request = require('request');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var http = require('http');
|
|
8
|
+
var net = require('net');
|
|
9
|
+
var nodeStatic = require('node-static');
|
|
10
|
+
var WebSocket = require('ws');
|
|
11
|
+
var Proxy = require('../');
|
|
12
|
+
var fileStaticA = new nodeStatic.Server(__dirname + '/wwwA');
|
|
13
|
+
var fileStaticB = new nodeStatic.Server(__dirname + '/wwwB');
|
|
14
|
+
var testHost = '127.0.0.1';
|
|
15
|
+
var testHostName = 'localhost';
|
|
16
|
+
var testPortA = 40005;
|
|
17
|
+
var testPortB = 40006;
|
|
18
|
+
var testProxyPort = 40010;
|
|
19
|
+
var testWSPort = 40007;
|
|
20
|
+
var testUrlA = 'http://' + testHost + ':' + testPortA;
|
|
21
|
+
var testUrlB = 'http://' + testHost + ':' + testPortB;
|
|
22
|
+
|
|
23
|
+
var getHttp = function (url, cb) {
|
|
24
|
+
request({ url: url }, function (err, resp, body) {
|
|
25
|
+
cb(err, resp, body);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var proxyHttp = function (url, keepAlive, cb) {
|
|
30
|
+
request({
|
|
31
|
+
url: url,
|
|
32
|
+
proxy: 'http://127.0.0.1:' + testProxyPort,
|
|
33
|
+
ca: fs.readFileSync(__dirname + '/../.http-mitm-proxy/certs/ca.pem'),
|
|
34
|
+
agentOptions: {
|
|
35
|
+
keepAlive: keepAlive
|
|
36
|
+
}
|
|
37
|
+
}, function (err, resp, body) {
|
|
38
|
+
cb(err, resp, body);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var countString = function (str, substr, cb) {
|
|
43
|
+
var pos = str.indexOf(substr);
|
|
44
|
+
var len = substr.length;
|
|
45
|
+
var count = 0;
|
|
46
|
+
if (pos > -1) {
|
|
47
|
+
var offSet = len;
|
|
48
|
+
while(pos !== -1) {
|
|
49
|
+
count++;
|
|
50
|
+
offSet = pos + len;
|
|
51
|
+
pos = str.indexOf(substr, offSet);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
cb(count);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
describe('proxy', function () {
|
|
58
|
+
this.timeout(30000);
|
|
59
|
+
var srvA = null;
|
|
60
|
+
var srvB = null;
|
|
61
|
+
var proxy = null;
|
|
62
|
+
var testHashes = {};
|
|
63
|
+
var testFiles = [
|
|
64
|
+
'1024.bin'
|
|
65
|
+
];
|
|
66
|
+
var wss = null;
|
|
67
|
+
|
|
68
|
+
before(function () {
|
|
69
|
+
testFiles.forEach(function (val) {
|
|
70
|
+
testHashes[val] = crypto.createHash('sha256').update(fs.readFileSync(__dirname + '/www/' + val, 'utf8'), 'utf8').digest().toString();
|
|
71
|
+
});
|
|
72
|
+
srvA = http.createServer(function (req, res) {
|
|
73
|
+
req.addListener('end', function () {
|
|
74
|
+
fileStaticA.serve(req, res);
|
|
75
|
+
}).resume();
|
|
76
|
+
});
|
|
77
|
+
srvA.listen(testPortA, testHost);
|
|
78
|
+
srvB = http.createServer(function (req, res) {
|
|
79
|
+
req.addListener('end', function () {
|
|
80
|
+
fileStaticB.serve(req, res);
|
|
81
|
+
}).resume();
|
|
82
|
+
});
|
|
83
|
+
srvB.listen(testPortB, testHost);
|
|
84
|
+
wss = new WebSocket.Server({
|
|
85
|
+
port: testWSPort,
|
|
86
|
+
});
|
|
87
|
+
wss.on('connection', function (ws) {
|
|
88
|
+
// just reply with the same message
|
|
89
|
+
ws.on('message', function (message) {
|
|
90
|
+
ws.send(message);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
beforeEach(function (done) {
|
|
96
|
+
proxy = new Proxy();
|
|
97
|
+
proxy.listen({ port: testProxyPort }, done);
|
|
98
|
+
proxy.onError(function (ctx, err, errorKind) {
|
|
99
|
+
var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : '';
|
|
100
|
+
console.log('proxy error: ' + errorKind + ' on ' + url + ':', err);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
afterEach(function () {
|
|
105
|
+
proxy.close();
|
|
106
|
+
proxy = null;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
after(function () {
|
|
110
|
+
srvA.close();
|
|
111
|
+
srvA = null;
|
|
112
|
+
srvB.close();
|
|
113
|
+
srvB = null;
|
|
114
|
+
wss.close();
|
|
115
|
+
wss = null;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('ca server', function () {
|
|
119
|
+
it('should generate a root CA file', function (done) {
|
|
120
|
+
fs.access(__dirname + '/../.http-mitm-proxy/certs/ca.pem', function (err) {
|
|
121
|
+
var rtv = null;
|
|
122
|
+
if (err) {
|
|
123
|
+
rtv = __dirname + '/../.http-mitm-proxy/certs/ca.pem ' + err;
|
|
124
|
+
} else {
|
|
125
|
+
rtv = true;
|
|
126
|
+
}
|
|
127
|
+
assert.equal(true, rtv, 'Can access the CA cert');
|
|
128
|
+
done();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('http server', function () {
|
|
134
|
+
describe('get a 1024 byte file', function () {
|
|
135
|
+
it('a', function (done) {
|
|
136
|
+
getHttp(testUrlA + '/1024.bin', function (err, resp, body) {
|
|
137
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
138
|
+
var len = 0;
|
|
139
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
140
|
+
assert.equal(1024, len, 'body length is 1024');
|
|
141
|
+
assert.equal(testHashes['1024.bin'], crypto.createHash('sha256').update(body, 'utf8').digest().toString(), 'sha256 hash matches');
|
|
142
|
+
done();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
it('b', function (done) {
|
|
146
|
+
getHttp(testUrlB + '/1024.bin', function (err, resp, body) {
|
|
147
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
148
|
+
var len = 0;
|
|
149
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
150
|
+
assert.equal(1024, len, 'body length is 1024');
|
|
151
|
+
assert.equal(testHashes['1024.bin'], crypto.createHash('sha256').update(body, 'utf8').digest().toString(), 'sha256 hash matches');
|
|
152
|
+
done();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('proxy server', function () {
|
|
159
|
+
this.timeout(5000);
|
|
160
|
+
|
|
161
|
+
it('should handle socket errors in connect', function(done) {
|
|
162
|
+
// If a socket disconnects during the CONNECT process, the resulting
|
|
163
|
+
// error should be handled and shouldn't cause the proxy server to fail.
|
|
164
|
+
const socket = net.createConnection(testProxyPort, testHost, function() {
|
|
165
|
+
socket.write('CONNECT ' + testHost + ':' + testPortA + '\r\n\r\n');
|
|
166
|
+
socket.destroy();
|
|
167
|
+
});
|
|
168
|
+
socket.on('close', function() {
|
|
169
|
+
proxyHttp(testUrlA + '/1024.bin', false, function (err, resp, body) {
|
|
170
|
+
if (err) {
|
|
171
|
+
return done(new Error(err.message + " " + JSON.stringify(err)));
|
|
172
|
+
}
|
|
173
|
+
var len = 0;
|
|
174
|
+
if (body.hasOwnProperty('length')) {
|
|
175
|
+
len = body.length;
|
|
176
|
+
}
|
|
177
|
+
assert.equal(1024, len);
|
|
178
|
+
assert.equal(testHashes['1024.bin'], crypto.createHash('sha256').update(body, 'utf8').digest().toString());
|
|
179
|
+
done();
|
|
180
|
+
});
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('proxy a 1024 byte file', function () {
|
|
185
|
+
it('a', function (done) {
|
|
186
|
+
proxyHttp(testUrlA + '/1024.bin', false, function (err, resp, body) {
|
|
187
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
188
|
+
var len = 0;
|
|
189
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
190
|
+
assert.equal(1024, len);
|
|
191
|
+
assert.equal(testHashes['1024.bin'], crypto.createHash('sha256').update(body, 'utf8').digest().toString());
|
|
192
|
+
done();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
it('b', function (done) {
|
|
196
|
+
proxyHttp(testUrlB + '/1024.bin', false, function (err, resp, body) {
|
|
197
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
198
|
+
var len = 0;
|
|
199
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
200
|
+
assert.equal(1024, len);
|
|
201
|
+
assert.equal(testHashes['1024.bin'], crypto.createHash('sha256').update(body, 'utf8').digest().toString());
|
|
202
|
+
done();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
describe('ssl', function () {
|
|
207
|
+
it('proxys to google.com using local ca file', function (done) {
|
|
208
|
+
proxyHttp('https://www.google.com/', false, function (err, resp, body) {
|
|
209
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
210
|
+
assert.equal(200, resp.statusCode, '200 Status code from Google.');
|
|
211
|
+
done();
|
|
212
|
+
});
|
|
213
|
+
}).timeout(15000);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('proxy a 1024 byte file with keepAlive', function () {
|
|
217
|
+
it('a', function (done) {
|
|
218
|
+
proxyHttp(testUrlA + '/1024.bin', true, function (err, resp, body) {
|
|
219
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
220
|
+
var len = 0;
|
|
221
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
222
|
+
assert.equal(1024, len);
|
|
223
|
+
assert.equal(testHashes['1024.bin'], crypto.createHash('sha256').update(body, 'utf8').digest().toString());
|
|
224
|
+
done();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
it('b', function (done) {
|
|
228
|
+
proxyHttp(testUrlB + '/1024.bin', true, function (err, resp, body) {
|
|
229
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
230
|
+
var len = 0;
|
|
231
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
232
|
+
assert.equal(1024, len);
|
|
233
|
+
assert.equal(testHashes['1024.bin'], crypto.createHash('sha256').update(body, 'utf8').digest().toString());
|
|
234
|
+
done();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('ssl with keepAlive', function () {
|
|
239
|
+
it('proxys to google.com using local ca file', function (done) {
|
|
240
|
+
proxyHttp('https://www.google.com/', true, function (err, resp, body) {
|
|
241
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
242
|
+
assert.equal(200, resp.statusCode, '200 Status code from Google.');
|
|
243
|
+
done();
|
|
244
|
+
});
|
|
245
|
+
}).timeout(15000);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('host match', function () {
|
|
249
|
+
it('proxy and modify AAA 5 times if hostA', function (done) {
|
|
250
|
+
proxy.onRequest(function (ctx, callback) {
|
|
251
|
+
var testHostNameA = '127.0.0.1:' + testPortA;
|
|
252
|
+
if (ctx.clientToProxyRequest.headers.host === testHostNameA) {
|
|
253
|
+
var chunks = [];
|
|
254
|
+
ctx.onResponseData(function (ctx, chunk, callback) {
|
|
255
|
+
chunks.push(chunk);
|
|
256
|
+
return callback(null, null);
|
|
257
|
+
});
|
|
258
|
+
ctx.onResponseEnd(function (ctx, callback) {
|
|
259
|
+
var body = (Buffer.concat(chunks)).toString();
|
|
260
|
+
for(var i = 0; i < 5; i++) {
|
|
261
|
+
var off = (i * 10);
|
|
262
|
+
body = body.substr(0, off) + 'AAA' + body.substr(off + 3);
|
|
263
|
+
}
|
|
264
|
+
ctx.proxyToClientResponse.write(body);
|
|
265
|
+
return callback();
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return callback();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
proxyHttp(testUrlA + '/1024.bin', false, function (err, resp, body) {
|
|
272
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
273
|
+
var len = 0;
|
|
274
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
275
|
+
assert.equal(1024, len);
|
|
276
|
+
countString(body, 'AAA', function (count) {
|
|
277
|
+
assert.equal(5, count);
|
|
278
|
+
proxyHttp(testUrlB + '/1024.bin', false, function (errB, respB, bodyB) {
|
|
279
|
+
if (errB) console.log('errB: ' + errB.toString());
|
|
280
|
+
var lenB = 0;
|
|
281
|
+
if (bodyB.hasOwnProperty('length')) lenB = bodyB.length;
|
|
282
|
+
assert.equal(1024, lenB);
|
|
283
|
+
countString(bodyB, 'AAA', function (countB) {
|
|
284
|
+
assert.equal(0, countB);
|
|
285
|
+
done();
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('chunked transfer', function () {
|
|
294
|
+
it('should not change transfer encoding when no content modification is active', function (done) {
|
|
295
|
+
proxyHttp(testUrlA + '/1024.bin', false, function (err, resp, body) {
|
|
296
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
297
|
+
var len = 0;
|
|
298
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
299
|
+
assert.equal(1024, len);
|
|
300
|
+
assert.equal(null, resp.headers['transfer-encoding']);
|
|
301
|
+
assert.equal(1024, resp.headers['content-length']);
|
|
302
|
+
done();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('should use chunked transfer encoding when global onResponseData is active', function (done) {
|
|
307
|
+
proxy.onResponseData(function (ctx, chunk, callback) {
|
|
308
|
+
callback(null, chunk);
|
|
309
|
+
});
|
|
310
|
+
proxyHttp(testUrlA + '/1024.bin', false, function (err, resp, body) {
|
|
311
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
312
|
+
var len = 0;
|
|
313
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
314
|
+
assert.equal(1024, len);
|
|
315
|
+
assert.equal('chunked', resp.headers['transfer-encoding']);
|
|
316
|
+
assert.equal(null, resp.headers['content-length']);
|
|
317
|
+
done();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('should use chunked transfer encoding when context onResponseData is active', function (done) {
|
|
322
|
+
proxy.onResponse(function (ctx, callback) {
|
|
323
|
+
ctx.onResponseData(function (ctx, chunk, callback) {
|
|
324
|
+
callback(null, chunk);
|
|
325
|
+
});
|
|
326
|
+
callback(null);
|
|
327
|
+
});
|
|
328
|
+
proxyHttp(testUrlA + '/1024.bin', false, function (err, resp, body) {
|
|
329
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
330
|
+
var len = 0;
|
|
331
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
332
|
+
assert.equal(1024, len);
|
|
333
|
+
assert.equal('chunked', resp.headers['transfer-encoding']);
|
|
334
|
+
assert.equal(null, resp.headers['content-length']);
|
|
335
|
+
done();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('should use chunked transfer encoding when context ResponseFilter is active', function (done) {
|
|
340
|
+
proxy.onResponse(function (ctx, callback) {
|
|
341
|
+
ctx.addResponseFilter(zlib.createGzip());
|
|
342
|
+
callback(null);
|
|
343
|
+
});
|
|
344
|
+
proxyHttp(testUrlA + '/1024.bin', false, function (err, resp, body) {
|
|
345
|
+
if (err) return done(new Error(err.message+" "+JSON.stringify(err)));
|
|
346
|
+
var len = 0;
|
|
347
|
+
if (body.hasOwnProperty('length')) len = body.length;
|
|
348
|
+
assert.equal(true, len < 1024); // Compressed body
|
|
349
|
+
assert.equal('chunked', resp.headers['transfer-encoding']);
|
|
350
|
+
assert.equal(null, resp.headers['content-length']);
|
|
351
|
+
done();
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe('websocket server', function() {
|
|
358
|
+
this.timeout(2000);
|
|
359
|
+
|
|
360
|
+
it('send + receive message without proxy', function (done) {
|
|
361
|
+
var ws = new WebSocket('ws://localhost:' + testWSPort);
|
|
362
|
+
var testMessage = 'does the websocket server reply?';
|
|
363
|
+
ws.on('open', function () {
|
|
364
|
+
ws.on('message', function (data) {
|
|
365
|
+
assert.equal(data, testMessage);
|
|
366
|
+
ws.close();
|
|
367
|
+
done();
|
|
368
|
+
});
|
|
369
|
+
ws.send(testMessage);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('send + receive message through proxy', function (done) {
|
|
374
|
+
var ws = new WebSocket('ws://localhost:' + testProxyPort, {
|
|
375
|
+
host: 'localhost:' + testWSPort,
|
|
376
|
+
});
|
|
377
|
+
var testMessage = 'does websocket proxying work?';
|
|
378
|
+
ws.on('open', function () {
|
|
379
|
+
ws.on('message', function (data) {
|
|
380
|
+
assert.equal(data, testMessage);
|
|
381
|
+
ws.close();
|
|
382
|
+
done();
|
|
383
|
+
});
|
|
384
|
+
ws.send(testMessage);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('websocket callbacks get called', function (done) {
|
|
389
|
+
var stats = {
|
|
390
|
+
connection: false,
|
|
391
|
+
frame: false,
|
|
392
|
+
send: false,
|
|
393
|
+
message: false,
|
|
394
|
+
close: false,
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
proxy.onWebSocketConnection(function (ctx, callback) {
|
|
398
|
+
stats.connection = true;
|
|
399
|
+
return callback();
|
|
400
|
+
});
|
|
401
|
+
proxy.onWebSocketFrame(function(ctx, type, fromServer, message, flags, callback) {
|
|
402
|
+
stats.frame = true;
|
|
403
|
+
message = rewrittenMessage;
|
|
404
|
+
return callback(null, message, flags);
|
|
405
|
+
});
|
|
406
|
+
proxy.onWebSocketSend(function(ctx, message, flags, callback) {
|
|
407
|
+
stats.send = true;
|
|
408
|
+
return callback(null, message, flags);
|
|
409
|
+
});
|
|
410
|
+
proxy.onWebSocketMessage(function(ctx, message, flags, callback) {
|
|
411
|
+
stats.message = true;
|
|
412
|
+
return callback(null, message, flags);
|
|
413
|
+
});
|
|
414
|
+
proxy.onWebSocketClose(function(ctx, code, message, callback) {
|
|
415
|
+
stats.close = true;
|
|
416
|
+
callback(null, code, message);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
var ws = new WebSocket('ws://localhost:' + testProxyPort, {
|
|
420
|
+
host: 'localhost:' + testWSPort,
|
|
421
|
+
});
|
|
422
|
+
var testMessage = 'does rewriting messages work?';
|
|
423
|
+
var rewrittenMessage = 'rewriting messages does work!';
|
|
424
|
+
ws.on('open', function () {
|
|
425
|
+
ws.on('message', function (data) {
|
|
426
|
+
assert.equal(data, rewrittenMessage);
|
|
427
|
+
ws.close();
|
|
428
|
+
});
|
|
429
|
+
ws.on('close', function () {
|
|
430
|
+
setTimeout(() => {
|
|
431
|
+
assert(stats.connection);
|
|
432
|
+
assert(stats.frame);
|
|
433
|
+
assert(stats.send);
|
|
434
|
+
assert(stats.message);
|
|
435
|
+
if (!stats.close) {
|
|
436
|
+
setTimeout(() => {
|
|
437
|
+
assert(stats.close);
|
|
438
|
+
done();
|
|
439
|
+
}, 500);
|
|
440
|
+
} else {
|
|
441
|
+
done();
|
|
442
|
+
}
|
|
443
|
+
}, 0);
|
|
444
|
+
});
|
|
445
|
+
ws.send(testMessage);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
123456789012345
|
|
2
|
+
123456789012345
|
|
3
|
+
123456789012345
|
|
4
|
+
123456789012345
|
|
5
|
+
123456789012345
|
|
6
|
+
123456789012345
|
|
7
|
+
123456789012345
|
|
8
|
+
123456789012345
|
|
9
|
+
123456789012345
|
|
10
|
+
123456789012345
|
|
11
|
+
123456789012345
|
|
12
|
+
123456789012345
|
|
13
|
+
123456789012345
|
|
14
|
+
123456789012345
|
|
15
|
+
123456789012345
|
|
16
|
+
123456789012345
|
|
17
|
+
123456789012345
|
|
18
|
+
123456789012345
|
|
19
|
+
123456789012345
|
|
20
|
+
123456789012345
|
|
21
|
+
123456789012345
|
|
22
|
+
123456789012345
|
|
23
|
+
123456789012345
|
|
24
|
+
123456789012345
|
|
25
|
+
123456789012345
|
|
26
|
+
123456789012345
|
|
27
|
+
123456789012345
|
|
28
|
+
123456789012345
|
|
29
|
+
123456789012345
|
|
30
|
+
123456789012345
|
|
31
|
+
123456789012345
|
|
32
|
+
123456789012345
|
|
33
|
+
123456789012345
|
|
34
|
+
123456789012345
|
|
35
|
+
123456789012345
|
|
36
|
+
123456789012345
|
|
37
|
+
123456789012345
|
|
38
|
+
123456789012345
|
|
39
|
+
123456789012345
|
|
40
|
+
123456789012345
|
|
41
|
+
123456789012345
|
|
42
|
+
123456789012345
|
|
43
|
+
123456789012345
|
|
44
|
+
123456789012345
|
|
45
|
+
123456789012345
|
|
46
|
+
123456789012345
|
|
47
|
+
123456789012345
|
|
48
|
+
123456789012345
|
|
49
|
+
123456789012345
|
|
50
|
+
123456789012345
|
|
51
|
+
123456789012345
|
|
52
|
+
123456789012345
|
|
53
|
+
123456789012345
|
|
54
|
+
123456789012345
|
|
55
|
+
123456789012345
|
|
56
|
+
123456789012345
|
|
57
|
+
123456789012345
|
|
58
|
+
123456789012345
|
|
59
|
+
123456789012345
|
|
60
|
+
123456789012345
|
|
61
|
+
123456789012345
|
|
62
|
+
123456789012345
|
|
63
|
+
123456789012345
|
|
64
|
+
123456789012345
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
123456789012345
|
|
2
|
+
123456789012345
|
|
3
|
+
123456789012345
|
|
4
|
+
123456789012345
|
|
5
|
+
123456789012345
|
|
6
|
+
123456789012345
|
|
7
|
+
123456789012345
|
|
8
|
+
123456789012345
|
|
9
|
+
123456789012345
|
|
10
|
+
123456789012345
|
|
11
|
+
123456789012345
|
|
12
|
+
123456789012345
|
|
13
|
+
123456789012345
|
|
14
|
+
123456789012345
|
|
15
|
+
123456789012345
|
|
16
|
+
123456789012345
|
|
17
|
+
123456789012345
|
|
18
|
+
123456789012345
|
|
19
|
+
123456789012345
|
|
20
|
+
123456789012345
|
|
21
|
+
123456789012345
|
|
22
|
+
123456789012345
|
|
23
|
+
123456789012345
|
|
24
|
+
123456789012345
|
|
25
|
+
123456789012345
|
|
26
|
+
123456789012345
|
|
27
|
+
123456789012345
|
|
28
|
+
123456789012345
|
|
29
|
+
123456789012345
|
|
30
|
+
123456789012345
|
|
31
|
+
123456789012345
|
|
32
|
+
123456789012345
|
|
33
|
+
123456789012345
|
|
34
|
+
123456789012345
|
|
35
|
+
123456789012345
|
|
36
|
+
123456789012345
|
|
37
|
+
123456789012345
|
|
38
|
+
123456789012345
|
|
39
|
+
123456789012345
|
|
40
|
+
123456789012345
|
|
41
|
+
123456789012345
|
|
42
|
+
123456789012345
|
|
43
|
+
123456789012345
|
|
44
|
+
123456789012345
|
|
45
|
+
123456789012345
|
|
46
|
+
123456789012345
|
|
47
|
+
123456789012345
|
|
48
|
+
123456789012345
|
|
49
|
+
123456789012345
|
|
50
|
+
123456789012345
|
|
51
|
+
123456789012345
|
|
52
|
+
123456789012345
|
|
53
|
+
123456789012345
|
|
54
|
+
123456789012345
|
|
55
|
+
123456789012345
|
|
56
|
+
123456789012345
|
|
57
|
+
123456789012345
|
|
58
|
+
123456789012345
|
|
59
|
+
123456789012345
|
|
60
|
+
123456789012345
|
|
61
|
+
123456789012345
|
|
62
|
+
123456789012345
|
|
63
|
+
123456789012345
|
|
64
|
+
123456789012345
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
123456789012345
|
|
2
|
+
123456789012345
|
|
3
|
+
123456789012345
|
|
4
|
+
123456789012345
|
|
5
|
+
123456789012345
|
|
6
|
+
123456789012345
|
|
7
|
+
123456789012345
|
|
8
|
+
123456789012345
|
|
9
|
+
123456789012345
|
|
10
|
+
123456789012345
|
|
11
|
+
123456789012345
|
|
12
|
+
123456789012345
|
|
13
|
+
123456789012345
|
|
14
|
+
123456789012345
|
|
15
|
+
123456789012345
|
|
16
|
+
123456789012345
|
|
17
|
+
123456789012345
|
|
18
|
+
123456789012345
|
|
19
|
+
123456789012345
|
|
20
|
+
123456789012345
|
|
21
|
+
123456789012345
|
|
22
|
+
123456789012345
|
|
23
|
+
123456789012345
|
|
24
|
+
123456789012345
|
|
25
|
+
123456789012345
|
|
26
|
+
123456789012345
|
|
27
|
+
123456789012345
|
|
28
|
+
123456789012345
|
|
29
|
+
123456789012345
|
|
30
|
+
123456789012345
|
|
31
|
+
123456789012345
|
|
32
|
+
123456789012345
|
|
33
|
+
123456789012345
|
|
34
|
+
123456789012345
|
|
35
|
+
123456789012345
|
|
36
|
+
123456789012345
|
|
37
|
+
123456789012345
|
|
38
|
+
123456789012345
|
|
39
|
+
123456789012345
|
|
40
|
+
123456789012345
|
|
41
|
+
123456789012345
|
|
42
|
+
123456789012345
|
|
43
|
+
123456789012345
|
|
44
|
+
123456789012345
|
|
45
|
+
123456789012345
|
|
46
|
+
123456789012345
|
|
47
|
+
123456789012345
|
|
48
|
+
123456789012345
|
|
49
|
+
123456789012345
|
|
50
|
+
123456789012345
|
|
51
|
+
123456789012345
|
|
52
|
+
123456789012345
|
|
53
|
+
123456789012345
|
|
54
|
+
123456789012345
|
|
55
|
+
123456789012345
|
|
56
|
+
123456789012345
|
|
57
|
+
123456789012345
|
|
58
|
+
123456789012345
|
|
59
|
+
123456789012345
|
|
60
|
+
123456789012345
|
|
61
|
+
123456789012345
|
|
62
|
+
123456789012345
|
|
63
|
+
123456789012345
|
|
64
|
+
123456789012345
|
|
File without changes
|