Compare commits

...

16 Commits

Author SHA1 Message Date
da19fab8d8 2.0.12 2021-02-03 11:02:26 +00:00
8d318dca28 fix(core): update 2021-02-03 11:02:26 +00:00
d03bfcc793 2.0.11 2021-02-03 01:14:10 +00:00
4ba2686977 fix(core): update 2021-02-03 01:14:09 +00:00
d24c4d4b7a 2.0.10 2021-02-03 00:30:35 +00:00
e1d4d6cf38 fix(core): update 2021-02-03 00:30:35 +00:00
11344ac0df 2.0.9 2021-02-03 00:23:29 +00:00
85fcfc3c36 fix(core): update 2021-02-03 00:23:28 +00:00
e9ac7b2347 2.0.8 2021-02-03 00:16:11 +00:00
2c59540768 fix(core): update 2021-02-03 00:16:11 +00:00
0f82d63f5c 2.0.7 2021-02-03 00:13:30 +00:00
b5fcdadd3d fix(core): update 2021-02-03 00:13:29 +00:00
6168b07414 2.0.6 2021-02-02 21:59:55 +00:00
588179335a fix(core): update 2021-02-02 21:59:54 +00:00
703cbedad4 2.0.5 2021-02-02 21:59:25 +00:00
dd7e9e8416 fix(core): update 2021-02-02 21:59:24 +00:00
5 changed files with 56 additions and 6 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "2.0.4", "version": "2.0.12",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "2.0.4", "version": "2.0.12",
"private": false, "private": false,
"description": "a proxy for handling high workloads of proxying", "description": "a proxy for handling high workloads of proxying",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -8,6 +8,7 @@ export class ProxyWorker {
public port = 8001; public port = 8001;
public router = new SmartproxyRouter(); public router = new SmartproxyRouter();
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>(); public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
public defaultHeaders: {[key: string]: string} = {};
/** /**
* starts the proxyInstance * starts the proxyInstance
@ -161,6 +162,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
{ {
method: req.method, method: req.method,
headers: req.headers, headers: req.headers,
keepAlive: true
}, },
true, // lets make this streaming true, // lets make this streaming
(request) => { (request) => {
@ -174,6 +176,9 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
); );
res.statusCode = response.statusCode; res.statusCode = response.statusCode;
console.log(response.statusCode); console.log(response.statusCode);
for (const defaultHeader of Object.keys(this.defaultHeaders)) {
res.setHeader(defaultHeader, this.defaultHeaders[defaultHeader]);
}
for (const header of Object.keys(response.headers)) { for (const header of Object.keys(response.headers)) {
res.setHeader(header, response.headers[header]); res.setHeader(header, response.headers[header]);
} }
@ -220,10 +225,24 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
this.httpsServer.keepAliveTimeout = 61000; this.httpsServer.keepAliveTimeout = 61000;
this.httpsServer.headersTimeout = 65000; this.httpsServer.headersTimeout = 65000;
this.httpsServer.on('connection', (connection) => { this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
connection.setTimeout(120000);
this.socketMap.add(connection); this.socketMap.add(connection);
connection.on('close', () => { connection.on('close', () => {
this.socketMap.remove(connection); this.socketMap.remove(connection);
connection.destroy();
});
connection.on('error', () => {
this.socketMap.remove(connection);
connection.destroy();
});
connection.on('end', () => {
this.socketMap.remove(connection);
connection.destroy();
});
connection.on('timeout', () => {
this.socketMap.remove(connection);
connection.destroy();
}); });
}); });
@ -270,6 +289,7 @@ const proxyWorkerCalls = {
updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => { updateReverseConfigs: async (configArray: plugins.tsclass.network.IReverseProxyConfig[]) => {
await proxyWorkerInstance.updateProxyConfigs(configArray); await proxyWorkerInstance.updateProxyConfigs(configArray);
}, },
addDefaultHeaders: async (headers: {[key: string]: string}) => {}
}; };
export type TProxyWorkerCalls = typeof proxyWorkerCalls; export type TProxyWorkerCalls = typeof proxyWorkerCalls;

View File

@ -45,6 +45,10 @@ export class SmartProxy {
console.log('successfully spawned portproxy and proxyworkers!'); console.log('successfully spawned portproxy and proxyworkers!');
} }
public async updateDefaultHeaders(defaultHeadersArg: {[key: string]: string}) {
await this.proxyWorkerFunctions.addDefaultHeaders(defaultHeadersArg);
}
public async stop() { public async stop() {
await this.proxyWorkerFunctions.stop(); await this.proxyWorkerFunctions.stop();
await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions); await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions);

View File

@ -18,23 +18,49 @@ const portProxyCalls = {
response.end(); response.end();
}); });
httpServer.listen(7999); httpServer.listen(7999);
const cleanUpSockets = (from: plugins.net.Socket, to: plugins.net.Socket) => {
from.end();
to.end();
from.removeAllListeners();
to.removeAllListeners();
from.unpipe();
to.unpipe();
from.destroy();
to.destroy();
}
netServer = net netServer = net
.createServer((from) => { .createServer((from) => {
const to = net.createConnection({ const to = net.createConnection({
host: 'localhost', host: 'localhost',
port: 8001, port: 8001,
}); });
from.setTimeout(120000);
from.pipe(to); from.pipe(to);
to.pipe(from); to.pipe(from);
from.on('error', () => { from.on('error', () => {
from.end(), to.end(); cleanUpSockets(from, to);
}); });
to.on('error', () => { to.on('error', () => {
from.end(), to.end(); cleanUpSockets(from, to);
}); });
from.on('close', () => { from.on('close', () => {
to.end(); cleanUpSockets(from, to);
}); });
to.on('close', () => {
cleanUpSockets(from, to);
});
from.on('timeout', () => {
cleanUpSockets(from, to);
});
to.on('timeout', () => {
cleanUpSockets(from, to);
});
from.on('end', () => {
cleanUpSockets(from, to);
})
to.on('end', () => {
cleanUpSockets(from, to);
})
}) })
.listen(portArg); .listen(portArg);
console.log(`PortProxy -> OK: Now listening on port ${portArg}`); console.log(`PortProxy -> OK: Now listening on port ${portArg}`);