forked from localtunnel/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework request proxy to use native http request and direct socket pipe. Cuts out bouncy which is no longer maintained and simplifies the code path.
- Loading branch information
1 parent
4f0f78d
commit f8fa049
Showing
7 changed files
with
195 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var http = require('http'); | ||
var util = require('util'); | ||
var assert = require('assert'); | ||
|
||
// binding agent will return a given options.socket as the socket for the agent | ||
// this is useful if you already have a socket established and want the request | ||
// to use that socket instead of making a new one | ||
function BindingAgent(options) { | ||
options = options || {}; | ||
http.Agent.call(this, options); | ||
|
||
this.socket = options.socket; | ||
assert(this.socket, 'socket is required for BindingAgent'); | ||
this.createConnection = create_connection; | ||
} | ||
|
||
util.inherits(BindingAgent, http.Agent); | ||
|
||
function create_connection(port, host, options) { | ||
return this.socket; | ||
} | ||
|
||
module.exports = BindingAgent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var http = require('http'); | ||
var url = require('url'); | ||
var assert = require('assert'); | ||
var localtunnel = require('localtunnel'); | ||
|
||
var localtunnel_server = require('../server')({ | ||
max_tcp_sockets: 2 | ||
}); | ||
|
||
var lt_server_port | ||
|
||
suite('simple'); | ||
|
||
test('set up localtunnel server', function(done) { | ||
var server = localtunnel_server.listen(function() { | ||
lt_server_port = server.address().port; | ||
done(); | ||
}); | ||
}); | ||
|
||
test('set up local http server', function(done) { | ||
var server = http.createServer(function(req, res) { | ||
res.end('hello world!'); | ||
}); | ||
|
||
server.listen(function() { | ||
test._fake_port = server.address().port; | ||
done(); | ||
}); | ||
}); | ||
|
||
test('set up localtunnel client', function(done) { | ||
var opt = { | ||
host: 'http://localhost:' + lt_server_port, | ||
}; | ||
|
||
localtunnel(test._fake_port, opt, function(err, tunnel) { | ||
assert.ifError(err); | ||
var url = tunnel.url; | ||
assert.ok(new RegExp('^http:\/\/.*localhost:' + lt_server_port + '$').test(url)); | ||
test._fake_url = url; | ||
done(err); | ||
}); | ||
}); | ||
|
||
test('should respond to request', function(done) { | ||
var hostname = url.parse(test._fake_url).hostname; | ||
var opt = { | ||
host: 'localhost', | ||
port: lt_server_port, | ||
headers: { | ||
host: hostname + '.tld' | ||
} | ||
}; | ||
|
||
http.get(opt, function(res) { | ||
var body = ''; | ||
res.setEncoding('utf-8'); | ||
res.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
|
||
res.on('end', function() { | ||
assert.equal(body, 'hello world!'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.