mirror of
https://github.com/bitinflow/localtunnel.git
synced 2026-03-13 13:35:54 +00:00
HTTPS support, Promise API, modern ES syntax
* Add support for tunneling a local HTTPS server. * Return a Promise from localtunnel.
This commit is contained in:
committed by
Roman Shtylman
parent
d7330a7121
commit
2a74d6be9f
@@ -1,39 +1,23 @@
|
||||
var stream = require('stream');
|
||||
var util = require('util');
|
||||
const { Transform } = require('stream');
|
||||
|
||||
var Transform = stream.Transform;
|
||||
class HeaderHostTransformer extends Transform {
|
||||
constructor(opts = {}) {
|
||||
super(opts);
|
||||
this.host = opts.host || 'localhost';
|
||||
this.replaced = false;
|
||||
}
|
||||
|
||||
var HeaderHostTransformer = function(opts) {
|
||||
if (!(this instanceof HeaderHostTransformer)) {
|
||||
return new HeaderHostTransformer(opts);
|
||||
}
|
||||
|
||||
opts = opts || {}
|
||||
Transform.call(this, opts);
|
||||
|
||||
var self = this;
|
||||
self.host = opts.host || 'localhost';
|
||||
self.replaced = false;
|
||||
_transform(data, encoding, callback) {
|
||||
callback(
|
||||
null,
|
||||
this.replaced // after replacing the first instance of the Host header we just become a regular passthrough
|
||||
? data
|
||||
: data.toString().replace(/(\r\n[Hh]ost: )\S+/, (match, $1) => {
|
||||
this.replaced = true;
|
||||
return $1 + this.host;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
util.inherits(HeaderHostTransformer, Transform);
|
||||
|
||||
HeaderHostTransformer.prototype._transform = function (chunk, enc, cb) {
|
||||
var self = this;
|
||||
|
||||
// after replacing the first instance of the Host header
|
||||
// we just become a regular passthrough
|
||||
if (!self.replaced) {
|
||||
chunk = chunk.toString();
|
||||
self.push(chunk.replace(/(\r\n[Hh]ost: )\S+/, function(match, $1) {
|
||||
self.replaced = true;
|
||||
return $1 + self.host;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
self.push(chunk);
|
||||
}
|
||||
|
||||
cb();
|
||||
};
|
||||
|
||||
module.exports = HeaderHostTransformer;
|
||||
|
||||
Reference in New Issue
Block a user