add https pc services support
This commit is contained in:
44
zefie_wtvp_minisrv/includes/classes/HTTPX.js
Normal file
44
zefie_wtvp_minisrv/includes/classes/HTTPX.js
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
let net = require('net');
|
||||
let http = require('http');
|
||||
let https = require('https');
|
||||
|
||||
exports.createServer = (opts, handler) => {
|
||||
|
||||
let server = net.createServer(socket => {
|
||||
socket.once('data', buffer => {
|
||||
// Pause the socket
|
||||
socket.pause();
|
||||
|
||||
// Determine if this is an HTTP(s) request
|
||||
let byte = buffer[0];
|
||||
|
||||
let protocol;
|
||||
if (byte === 22) {
|
||||
protocol = 'https';
|
||||
} else if (32 < byte && byte < 127) {
|
||||
protocol = 'http';
|
||||
}
|
||||
|
||||
let proxy = server[protocol];
|
||||
if (proxy) {
|
||||
// Push the buffer back onto the front of the data stream
|
||||
socket.unshift(buffer);
|
||||
|
||||
// Emit the socket to the HTTP(s) server
|
||||
proxy.emit('connection', socket);
|
||||
}
|
||||
|
||||
// As of NodeJS 10.x the socket must be
|
||||
// resumed asynchronously or the socket
|
||||
// connection hangs, potentially crashing
|
||||
// the process. Prior to NodeJS 10.x
|
||||
// the socket may be resumed synchronously.
|
||||
process.nextTick(() => socket.resume());
|
||||
});
|
||||
});
|
||||
|
||||
server.http = http.createServer(handler);
|
||||
server.https = https.createServer(opts, handler);
|
||||
return server;
|
||||
};
|
||||
@@ -62,6 +62,14 @@ class WTVShared {
|
||||
else return out;
|
||||
}
|
||||
|
||||
parseConfigVars(s) {
|
||||
if (s.indexOf("%ServiceDeps%") >= 0) {
|
||||
return this.getServiceDep(s.replace("%ServiceDeps%", ""), true);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
atob(a) {
|
||||
const CryptoJS = require('crypto-js');
|
||||
const enc = CryptoJS.enc.Base64.parse(a);
|
||||
|
||||
Reference in New Issue
Block a user