From 04c10113f7a3b568fb95b18f30e4aca3e059d961 Mon Sep 17 00:00:00 2001 From: cronopio Date: Mon, 11 Nov 2013 11:14:42 -0500 Subject: [PATCH] [examples] added concurrent proxy example --- examples/concurrent-proxy.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/concurrent-proxy.js diff --git a/examples/concurrent-proxy.js b/examples/concurrent-proxy.js new file mode 100644 index 0000000..0d1889f --- /dev/null +++ b/examples/concurrent-proxy.js @@ -0,0 +1,36 @@ +var http = require('http'), + httpProxy = require('../lib/http-proxy'); + +var connections = [], + go; + + +// +// Target Http Server +// +// to check apparent problems with concurrent connections +// make a server which only responds when there is a given nubmer on connections +// +http.createServer(function (req, res) { + connections.push(function () { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); + res.end(); + }); + + process.stdout.write(connections.length + ', '); + + if (connections.length > 10 || go) { + go = true; + while (connections.length) { + connections.shift()(); + } + } +}).listen(9000); +console.log("Web server listening on port 9000"); + +// +// Basic Http Proxy Server +// +httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000); +console.log("Proxy server listening on port 8000"); \ No newline at end of file