localtunnel
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -33,6 +33,12 @@ var net = require('net'); | ||
// we just become a regular passthrough | ||
self.push(chunk.replace(/(\r\nHost: )\S+/, function(match, $1) { | ||
self._transform = undefined; | ||
return $1 + self.host; | ||
})); | ||
if (!self.replaced) { | ||
self.push(chunk.replace(/(\r\nHost: )\S+/, function(match, $1) { | ||
self.replaced = true; | ||
return $1 + self.host; | ||
})); | ||
} | ||
else { | ||
self.push(chunk); | ||
} | ||
cb(); | ||
@@ -64,3 +70,3 @@ }; | ||
var local_host = opt.local_host; | ||
var local_host = opt.local_host || 'localhost'; | ||
var local_port = opt.local_port; | ||
@@ -138,6 +144,7 @@ | ||
// if user requested something other than localhost | ||
// if user requested specific local host | ||
// then we use host header transform to replace the host header | ||
if (local_host !== 'localhost') { | ||
stream = remote.pipe(HeaderHostTransformer({ host: local_host })); | ||
if (opt.local_host) { | ||
debug('transform Host header to %s', opt.local_host); | ||
stream = remote.pipe(HeaderHostTransformer({ host: opt.local_host })); | ||
} | ||
@@ -230,3 +237,3 @@ | ||
info.local_host = opt.local_host || 'localhost'; | ||
info.local_host = opt.local_host; | ||
info.local_port = opt.port; | ||
@@ -233,0 +240,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "expose localhost to the world", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -71,6 +71,50 @@ var http = require('http'); | ||
suite('local-host'); | ||
suite('--local-host localhost'); | ||
test('setup localtunnel client', function(done) { | ||
var opt = { | ||
local_host: 'localhost' | ||
}; | ||
localtunnel(test._fake_port, opt, function(err, tunnel) { | ||
assert.ifError(err); | ||
assert.ok(new RegExp('^https:\/\/.*localtunnel.me' + '$').test(tunnel.url)); | ||
test._fake_url = tunnel.url; | ||
done(); | ||
}); | ||
}); | ||
test('override Host header with local-host', function(done) { | ||
var uri = test._fake_url; | ||
var parsed = url.parse(uri); | ||
var opt = { | ||
host: parsed.host, | ||
port: 443, | ||
headers: { | ||
host: parsed.hostname | ||
}, | ||
path: '/' | ||
}; | ||
var req = https.request(opt, function(res) { | ||
res.setEncoding('utf8'); | ||
var body = ''; | ||
res.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
res.on('end', function() { | ||
assert.equal(body, 'localhost'); | ||
done(); | ||
}); | ||
}); | ||
req.end(); | ||
}); | ||
suite('--local-host 127.0.0.1'); | ||
test('setup localtunnel client', function(done) { | ||
var opt = { | ||
local_host: '127.0.0.1' | ||
@@ -115,1 +159,32 @@ }; | ||
}); | ||
test('send chunked request', function(done) { | ||
var uri = test._fake_url; | ||
var parsed = url.parse(uri); | ||
var opt = { | ||
host: parsed.host, | ||
port: 443, | ||
headers: { | ||
host: parsed.hostname, | ||
'Transfer-Encoding': 'chunked' | ||
}, | ||
path: '/' | ||
}; | ||
var req = https.request(opt, function(res) { | ||
res.setEncoding('utf8'); | ||
var body = ''; | ||
res.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
res.on('end', function() { | ||
assert.equal(body, '127.0.0.1'); | ||
done(); | ||
}); | ||
}); | ||
req.end(require('crypto').randomBytes(1024 * 8).toString('base64')); | ||
}); |
Sorry, the diff of this file is not supported yet
17686
405