Skip to content

Commit

Permalink
[doc api test] Rename HttpProxy.pause to HttpProxy.resume. Update doc…
Browse files Browse the repository at this point in the history
…umentation and tests accordingly
  • Loading branch information
indexzero committed Mar 10, 2011
1 parent 3bc7d16 commit 4110448
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 79 deletions.
50 changes: 36 additions & 14 deletions README.md
Expand Up @@ -47,11 +47,14 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
<pre>
var http = require('http'),
httpProxy = require('http-proxy');

//
// Create your proxy server
//
httpProxy.createServer(9000, 'localhost').listen(8000);

//
// Create your target server
//
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
Expand All @@ -63,11 +66,15 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
<pre>
var http = require('http'),
httpProxy = require('http-proxy');

// create a proxy server with custom application logic

//
// Create a proxy server with custom application logic
//
httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
proxy.proxyRequest(9000, 'localhost');
//
proxy.proxyRequest(req, res, 9000, 'localhost');
}).listen(8000);

http.createServer(function (req, res) {
Expand All @@ -81,13 +88,23 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
<pre>
var http = require('http'),
httpProxy = require('http-proxy');

// create a proxy server with custom application logic

//
// Create a proxy server with custom application logic
//
httpProxy.createServer(function (req, res, proxy) {
//
// Buffer the request so that `data` and `end` events
// are not lost during async operation(s).
//
var buffer = proxy.buffer(req);

//
// Wait for two seconds then respond: this simulates
// performing async actions before proxying a request
//
setTimeout(function () {
proxy.proxyRequest(9000, 'localhost');
proxy.proxyRequest(req, res, 9000, 'localhost', buffer);
}, 2000);
}).listen(8000);

Expand All @@ -102,15 +119,20 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
<pre>
var http = require('http'),
httpProxy = require('http-proxy');

// create a regular http server and proxy its handler

//
// Create a new instance of HttProxy to use in your server
//
var proxy = new httpProxy.HttpProxy();

//
// Create a regular http server and proxy its handler
//
http.createServer(function (req, res) {
// Create a new instance of HttProxy for this request
// each instance is only valid for serving one request
var proxy = new httpProxy.HttpProxy(req, res);

//
// Put your custom server logic here, then proxy
proxy.proxyRequest(9000, 'localhost', req, res);
//
proxy.proxyRequest(req, res, 9000, 'localhost');
}).listen(8001);

http.createServer(function (req, res) {
Expand Down
5 changes: 2 additions & 3 deletions bin/node-http-proxy
Expand Up @@ -9,7 +9,7 @@ var path = require('path'),
var help = [
"usage: node-http-proxy [options] ",
"",
"All options should be set with the syntax --option=value",
"Starts a node-http-proxy server using the specified command-line options",
"",
"options:",
" --port PORT Port that the proxy server should run on",
Expand All @@ -20,8 +20,7 @@ var help = [
].join('\n');

if (argv.h || argv.help || Object.keys(argv).length === 2) {
util.puts(help);
process.exit(0);
return util.puts(help);
}

var location, config = {},
Expand Down
8 changes: 4 additions & 4 deletions demo.js
Expand Up @@ -59,9 +59,9 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue +
// Http Proxy Server with Latency
//
httpProxy.createServer(function (req, res, proxy) {
var paused = proxy.pause(req);
var buffer = proxy.buffer(req);
setTimeout(function() {
proxy.proxyRequest(req, res, 9000, 'localhost', paused);
proxy.proxyRequest(req, res, 9000, 'localhost', buffer);
}, 200)
}).listen(8002);
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline);
Expand All @@ -82,9 +82,9 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue +
//
var standAloneProxy = new httpProxy.HttpProxy();
http.createServer(function (req, res) {
var paused = standAloneProxy.pause(req);
var buffer = standAloneProxy.buffer(req);
setTimeout(function() {
proxy.proxyRequest(req, res, 9000, 'localhost', paused);
proxy.proxyRequest(req, res, 9000, 'localhost', buffer);
}, 200);
}).listen(8004);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
Expand Down

0 comments on commit 4110448

Please sign in to comment.