add secure parameter to force https
This commit is contained in:
@@ -13,6 +13,7 @@ class Client extends EventEmitter {
|
||||
|
||||
const agent = this.agent = options.agent;
|
||||
const id = this.id = options.id;
|
||||
const secure = this.secure = options.secure;
|
||||
|
||||
this.debug = Debug(`lt:Client[${this.id}]`);
|
||||
|
||||
@@ -56,6 +57,14 @@ class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
handleRequest(req, res) {
|
||||
if(!req.secure && this.secure) {
|
||||
// Must redirect to https
|
||||
this.debug('Redirect to https > %s', req.url);
|
||||
let urlObject = url.parse('http://' + this.request.header.host);
|
||||
let httpsHost = urlObject.hostname;
|
||||
res.redirect('https://' + httpsHost + this.request.url);
|
||||
}
|
||||
|
||||
this.debug('> %s', req.url);
|
||||
const opt = {
|
||||
path: req.url,
|
||||
|
||||
@@ -28,7 +28,7 @@ class ClientManager {
|
||||
// create a new tunnel with `id`
|
||||
// if the id is already used, a random id is assigned
|
||||
// if the tunnel could not be created, throws an error
|
||||
async newClient(id) {
|
||||
async newClient(id, secure) {
|
||||
const clients = this.clients;
|
||||
const stats = this.stats;
|
||||
|
||||
@@ -46,6 +46,7 @@ class ClientManager {
|
||||
const client = new Client({
|
||||
id,
|
||||
agent,
|
||||
secure,
|
||||
});
|
||||
|
||||
// add to clients map immediately
|
||||
|
||||
Reference in New Issue
Block a user