@push.rocks/smartproxy 3.0.58 → 3.0.61
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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -0
- package/dist/smartproxy.classes.proxyworker.d.ts +23 -0
- package/dist/smartproxy.classes.proxyworker.js +262 -0
- package/dist/smartproxy.classes.router.d.ts +16 -0
- package/dist/smartproxy.classes.router.js +41 -0
- package/dist/smartproxy.classes.smartproxy.d.ts +17 -0
- package/dist/smartproxy.classes.smartproxy.js +43 -0
- package/dist/smartproxy.plugins.d.ts +17 -0
- package/dist/smartproxy.plugins.js +43 -0
- package/dist/smartproxy.portproxy.d.ts +6 -0
- package/dist/smartproxy.portproxy.js +38 -0
- package/dist_ts/00_commitinfo_data.d.ts +1 -1
- package/dist_ts/00_commitinfo_data.js +4 -4
- package/dist_ts/index.js +1 -1
- package/dist_ts/smartproxy.classes.networkproxy.js +81 -63
- package/dist_ts/smartproxy.classes.proxyworker.d.ts +33 -0
- package/dist_ts/smartproxy.classes.proxyworker.js +303 -0
- package/dist_ts/smartproxy.classes.router.js +2 -2
- package/dist_ts/smartproxy.classes.smartproxy.d.ts +20 -0
- package/dist_ts/smartproxy.classes.smartproxy.js +38 -0
- package/dist_ts/smartproxy.plugins.d.ts +5 -5
- package/dist_ts/smartproxy.plugins.js +6 -6
- package/npmextra.json +20 -4
- package/package.json +39 -21
- package/readme.hints.md +1 -0
- package/readme.md +109 -32
- package/ts/00_commitinfo_data.ts +3 -3
- package/ts/index.ts +1 -1
- package/ts/smartproxy.classes.networkproxy.ts +131 -101
- package/ts/smartproxy.classes.sslredirect.ts +1 -1
- package/ts/smartproxy.plugins.ts +5 -5
|
@@ -129,16 +129,20 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|
|
129
129
|
originResponse.writeHead(statusArg, messageArg);
|
|
130
130
|
originResponse.end(messageArg);
|
|
131
131
|
if (originRequest.socket !== originResponse.socket) {
|
|
132
|
-
console.log('hey, something is strange.')
|
|
132
|
+
console.log('hey, something is strange.');
|
|
133
133
|
}
|
|
134
134
|
originResponse.destroy();
|
|
135
135
|
};
|
|
136
136
|
|
|
137
|
-
console.log(
|
|
137
|
+
console.log(
|
|
138
|
+
`got request: ${originRequest.headers.host}${plugins.url.parse(originRequest.url).path}`
|
|
139
|
+
);
|
|
138
140
|
const destinationConfig = this.router.routeReq(originRequest);
|
|
139
141
|
|
|
140
142
|
if (!destinationConfig) {
|
|
141
|
-
console.log(
|
|
143
|
+
console.log(
|
|
144
|
+
`${originRequest.headers.host} can't be routed properly. Terminating request.`
|
|
145
|
+
);
|
|
142
146
|
endOriginReqRes();
|
|
143
147
|
return;
|
|
144
148
|
}
|
|
@@ -182,114 +186,140 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|
|
182
186
|
return endOriginReqRes();
|
|
183
187
|
}
|
|
184
188
|
console.log(destinationUrl);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
try {
|
|
190
|
+
const proxyResponse = await plugins.smartrequest.request(
|
|
191
|
+
destinationUrl,
|
|
192
|
+
{
|
|
193
|
+
method: originRequest.method,
|
|
194
|
+
headers: {
|
|
195
|
+
...originRequest.headers,
|
|
196
|
+
'X-Forwarded-Host': originRequest.headers.host,
|
|
197
|
+
'X-Forwarded-Proto': 'https',
|
|
198
|
+
},
|
|
199
|
+
keepAlive: true,
|
|
193
200
|
},
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
201
|
+
true, // lets make this streaming
|
|
202
|
+
(proxyRequest) => {
|
|
203
|
+
originRequest.on('data', (data) => {
|
|
204
|
+
proxyRequest.write(data);
|
|
205
|
+
});
|
|
206
|
+
originRequest.on('end', () => {
|
|
207
|
+
proxyRequest.end();
|
|
208
|
+
});
|
|
209
|
+
originRequest.on('error', () => {
|
|
210
|
+
proxyRequest.end();
|
|
211
|
+
});
|
|
212
|
+
originRequest.on('close', () => {
|
|
213
|
+
proxyRequest.end();
|
|
214
|
+
});
|
|
215
|
+
originRequest.on('timeout', () => {
|
|
216
|
+
proxyRequest.end();
|
|
217
|
+
originRequest.destroy();
|
|
218
|
+
});
|
|
219
|
+
proxyRequest.on('error', () => {
|
|
220
|
+
endOriginReqRes();
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
originResponse.statusCode = proxyResponse.statusCode;
|
|
225
|
+
console.log(proxyResponse.statusCode);
|
|
226
|
+
for (const defaultHeader of Object.keys(this.defaultHeaders)) {
|
|
227
|
+
originResponse.setHeader(defaultHeader, this.defaultHeaders[defaultHeader]);
|
|
217
228
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
for (const header of Object.keys(proxyResponse.headers)) {
|
|
230
|
+
originResponse.setHeader(header, proxyResponse.headers[header]);
|
|
231
|
+
}
|
|
232
|
+
proxyResponse.on('data', (data) => {
|
|
233
|
+
originResponse.write(data);
|
|
234
|
+
});
|
|
235
|
+
proxyResponse.on('end', () => {
|
|
236
|
+
originResponse.end();
|
|
237
|
+
});
|
|
238
|
+
proxyResponse.on('error', () => {
|
|
239
|
+
originResponse.destroy();
|
|
240
|
+
});
|
|
241
|
+
proxyResponse.on('close', () => {
|
|
242
|
+
originResponse.end();
|
|
243
|
+
});
|
|
244
|
+
proxyResponse.on('timeout', () => {
|
|
245
|
+
originResponse.end();
|
|
246
|
+
originResponse.destroy();
|
|
247
|
+
});
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.error('Error while processing request:', error);
|
|
250
|
+
endOriginReqRes(502, 'Bad Gateway: Error processing the request');
|
|
226
251
|
}
|
|
227
|
-
proxyResponse.on('data', (data) => {
|
|
228
|
-
originResponse.write(data);
|
|
229
|
-
});
|
|
230
|
-
proxyResponse.on('end', () => {
|
|
231
|
-
originResponse.end();
|
|
232
|
-
});
|
|
233
|
-
proxyResponse.on('error', () => {
|
|
234
|
-
originResponse.destroy();
|
|
235
|
-
});
|
|
236
|
-
proxyResponse.on('close', () => {
|
|
237
|
-
originResponse.end();
|
|
238
|
-
});
|
|
239
|
-
proxyResponse.on('timeout', () => {
|
|
240
|
-
originResponse.end();
|
|
241
|
-
originResponse.destroy()
|
|
242
|
-
});
|
|
243
|
-
|
|
244
252
|
}
|
|
245
253
|
);
|
|
246
254
|
|
|
247
255
|
// Enable websockets
|
|
248
|
-
const wsServer = new plugins.ws.WebSocketServer({ server: this.httpsServer
|
|
249
|
-
wsServer.on(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
256
|
+
const wsServer = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
|
257
|
+
wsServer.on(
|
|
258
|
+
'connection',
|
|
259
|
+
async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
|
260
|
+
console.log(
|
|
261
|
+
`wss proxy: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`
|
|
262
|
+
);
|
|
253
263
|
|
|
254
|
-
|
|
264
|
+
let wsOutgoing: plugins.wsDefault;
|
|
255
265
|
|
|
256
|
-
|
|
257
|
-
wsOutgoing = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
|
|
258
|
-
console.log('wss proxy: initiated outgoing proxy');
|
|
259
|
-
wsOutgoing.on('open', async () => {
|
|
260
|
-
outGoingDeferred.resolve();
|
|
261
|
-
})
|
|
262
|
-
} catch (err) {
|
|
263
|
-
console.log(err);
|
|
264
|
-
wsIncoming.terminate();
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
266
|
+
const outGoingDeferred = plugins.smartpromise.defer();
|
|
267
267
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
wsIncoming.on("close", () => terminateWsOutgoing());
|
|
268
|
+
try {
|
|
269
|
+
wsOutgoing = new plugins.wsDefault(
|
|
270
|
+
`ws://${this.router.routeReq(reqArg).destinationIp}:${
|
|
271
|
+
this.router.routeReq(reqArg).destinationPort
|
|
272
|
+
}${reqArg.url}`
|
|
273
|
+
);
|
|
274
|
+
console.log('wss proxy: initiated outgoing proxy');
|
|
275
|
+
wsOutgoing.on('open', async () => {
|
|
276
|
+
outGoingDeferred.resolve();
|
|
277
|
+
});
|
|
278
|
+
} catch (err) {
|
|
279
|
+
console.log(err);
|
|
280
|
+
wsIncoming.terminate();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
284
283
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
wsIncoming.on('message', async (message, isBinary) => {
|
|
285
|
+
try {
|
|
286
|
+
await outGoingDeferred.promise;
|
|
287
|
+
wsOutgoing.send(message, { binary: isBinary });
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.error('Error sending message to wsOutgoing:', error);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
wsOutgoing.on('message', async (message, isBinary) => {
|
|
294
|
+
try {
|
|
295
|
+
wsIncoming.send(message, { binary: isBinary });
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.error('Error sending message to wsIncoming:', error);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const terminateWsOutgoing = () => {
|
|
302
|
+
if (wsOutgoing) {
|
|
303
|
+
wsOutgoing.terminate();
|
|
304
|
+
console.log('terminated outgoing ws.');
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
wsIncoming.on('error', () => terminateWsOutgoing());
|
|
308
|
+
wsIncoming.on('close', () => terminateWsOutgoing());
|
|
309
|
+
|
|
310
|
+
const terminateWsIncoming = () => {
|
|
311
|
+
if (wsIncoming) {
|
|
312
|
+
wsIncoming.terminate();
|
|
313
|
+
console.log('terminated incoming ws.');
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
wsOutgoing.on('error', () => terminateWsIncoming());
|
|
317
|
+
wsOutgoing.on('close', () => terminateWsIncoming());
|
|
318
|
+
|
|
319
|
+
|
|
288
320
|
}
|
|
289
|
-
|
|
290
|
-
wsOutgoing.on("close", () => terminateWsIncoming());
|
|
321
|
+
);
|
|
291
322
|
|
|
292
|
-
});
|
|
293
323
|
this.httpsServer.keepAliveTimeout = 600 * 1000;
|
|
294
324
|
this.httpsServer.headersTimeout = 600 * 1000;
|
|
295
325
|
|
|
@@ -314,7 +344,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|
|
314
344
|
});
|
|
315
345
|
connection.on('timeout', () => {
|
|
316
346
|
cleanupConnection();
|
|
317
|
-
})
|
|
347
|
+
});
|
|
318
348
|
});
|
|
319
349
|
|
|
320
350
|
this.httpsServer.listen(this.options.port);
|
|
@@ -349,7 +379,6 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|
|
349
379
|
cert: hostCandidate.publicKey,
|
|
350
380
|
key: hostCandidate.privateKey,
|
|
351
381
|
});
|
|
352
|
-
this.httpsServer;
|
|
353
382
|
}
|
|
354
383
|
}
|
|
355
384
|
|
|
@@ -368,5 +397,6 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|
|
368
397
|
socket.destroy();
|
|
369
398
|
});
|
|
370
399
|
await done.promise;
|
|
400
|
+
console.log('NetworkProxy -> OK: Server has been stopped and all connections closed.');
|
|
371
401
|
}
|
|
372
|
-
}
|
|
402
|
+
}
|
package/ts/smartproxy.plugins.ts
CHANGED
|
@@ -12,11 +12,11 @@ import * as tsclass from '@tsclass/tsclass';
|
|
|
12
12
|
export { tsclass };
|
|
13
13
|
|
|
14
14
|
// pushrocks scope
|
|
15
|
-
import * as lik from '@
|
|
16
|
-
import * as smartdelay from '@
|
|
17
|
-
import * as smartpromise from '@
|
|
18
|
-
import * as smartrequest from '@
|
|
19
|
-
import * as smartstring from '@
|
|
15
|
+
import * as lik from '@push.rocks/lik';
|
|
16
|
+
import * as smartdelay from '@push.rocks/smartdelay';
|
|
17
|
+
import * as smartpromise from '@push.rocks/smartpromise';
|
|
18
|
+
import * as smartrequest from '@push.rocks/smartrequest';
|
|
19
|
+
import * as smartstring from '@push.rocks/smartstring';
|
|
20
20
|
|
|
21
21
|
export { lik, smartdelay, smartrequest, smartpromise, smartstring };
|
|
22
22
|
|