Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
da19fab8d8 | |||
8d318dca28 | |||
d03bfcc793 | |||
4ba2686977 | |||
d24c4d4b7a | |||
e1d4d6cf38 | |||
11344ac0df | |||
85fcfc3c36 | |||
e9ac7b2347 | |||
2c59540768 | |||
0f82d63f5c | |||
b5fcdadd3d |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "2.0.6",
|
||||
"version": "2.0.12",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartproxy",
|
||||
"version": "2.0.6",
|
||||
"version": "2.0.12",
|
||||
"private": false,
|
||||
"description": "a proxy for handling high workloads of proxying",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -8,6 +8,7 @@ export class ProxyWorker {
|
||||
public port = 8001;
|
||||
public router = new SmartproxyRouter();
|
||||
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
|
||||
public defaultHeaders: {[key: string]: string} = {};
|
||||
|
||||
/**
|
||||
* starts the proxyInstance
|
||||
@ -161,6 +162,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
{
|
||||
method: req.method,
|
||||
headers: req.headers,
|
||||
keepAlive: true
|
||||
},
|
||||
true, // lets make this streaming
|
||||
(request) => {
|
||||
@ -174,6 +176,9 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
);
|
||||
res.statusCode = 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)) {
|
||||
res.setHeader(header, response.headers[header]);
|
||||
}
|
||||
@ -220,10 +225,24 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
this.httpsServer.keepAliveTimeout = 61000;
|
||||
this.httpsServer.headersTimeout = 65000;
|
||||
|
||||
this.httpsServer.on('connection', (connection) => {
|
||||
this.httpsServer.on('connection', (connection: plugins.net.Socket) => {
|
||||
connection.setTimeout(120000);
|
||||
this.socketMap.add(connection);
|
||||
connection.on('close', () => {
|
||||
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[]) => {
|
||||
await proxyWorkerInstance.updateProxyConfigs(configArray);
|
||||
},
|
||||
addDefaultHeaders: async (headers: {[key: string]: string}) => {}
|
||||
};
|
||||
|
||||
export type TProxyWorkerCalls = typeof proxyWorkerCalls;
|
||||
|
@ -45,6 +45,10 @@ export class SmartProxy {
|
||||
console.log('successfully spawned portproxy and proxyworkers!');
|
||||
}
|
||||
|
||||
public async updateDefaultHeaders(defaultHeadersArg: {[key: string]: string}) {
|
||||
await this.proxyWorkerFunctions.addDefaultHeaders(defaultHeadersArg);
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.proxyWorkerFunctions.stop();
|
||||
await plugins.smartspawn.Thread.terminate(this.proxyWorkerFunctions);
|
||||
|
@ -25,6 +25,8 @@ const portProxyCalls = {
|
||||
to.removeAllListeners();
|
||||
from.unpipe();
|
||||
to.unpipe();
|
||||
from.destroy();
|
||||
to.destroy();
|
||||
}
|
||||
netServer = net
|
||||
.createServer((from) => {
|
||||
@ -32,6 +34,7 @@ const portProxyCalls = {
|
||||
host: 'localhost',
|
||||
port: 8001,
|
||||
});
|
||||
from.setTimeout(120000);
|
||||
from.pipe(to);
|
||||
to.pipe(from);
|
||||
from.on('error', () => {
|
||||
|
Reference in New Issue
Block a user