mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[minor doc] Update demo and small fix to node-http-proxy
This commit is contained in:
parent
389159da1b
commit
d8c54063dc
9
demo.js
9
demo.js
@ -60,8 +60,9 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue +
|
|||||||
// Http Proxy Server with Latency
|
// Http Proxy Server with Latency
|
||||||
//
|
//
|
||||||
httpProxy.createServer(function (req, res, proxy) {
|
httpProxy.createServer(function (req, res, proxy) {
|
||||||
|
var paused = proxy.pause(req);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
proxy.proxyRequest(9000, 'localhost');
|
proxy.proxyRequest(req, res, 9000, 'localhost', paused);
|
||||||
}, 200)
|
}, 200)
|
||||||
}).listen(8002);
|
}).listen(8002);
|
||||||
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline);
|
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline);
|
||||||
@ -80,11 +81,11 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue +
|
|||||||
//
|
//
|
||||||
// Http Server with proxyRequest Handler and Latency
|
// Http Server with proxyRequest Handler and Latency
|
||||||
//
|
//
|
||||||
|
var standAloneProxy = new httpProxy.HttpProxy();
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
var proxy = new httpProxy.HttpProxy(req, res);
|
var paused = standAloneProxy.pause(req);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
proxy.proxyRequest(9000, 'localhost');
|
proxy.proxyRequest(req, res, 9000, 'localhost', paused);
|
||||||
}, 200);
|
}, 200);
|
||||||
}).listen(8004);
|
}).listen(8004);
|
||||||
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
|
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
|
||||||
|
|||||||
@ -114,6 +114,8 @@ exports.createServer = function () {
|
|||||||
|
|
||||||
var HttpProxy = exports.HttpProxy = function (options) {
|
var HttpProxy = exports.HttpProxy = function (options) {
|
||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
if (options.router) {
|
if (options.router) {
|
||||||
@ -184,7 +186,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, paused) {
|
|||||||
// always ignore the proxyTable if an explicit `port` and `host`
|
// always ignore the proxyTable if an explicit `port` and `host`
|
||||||
// arguments are supplied to `proxyRequest`.
|
// arguments are supplied to `proxyRequest`.
|
||||||
//
|
//
|
||||||
|
|
||||||
if (this.proxyTable && !host) {
|
if (this.proxyTable && !host) {
|
||||||
location = this.proxyTable.getProxyLocation(req);
|
location = this.proxyTable.getProxyLocation(req);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user