Skip to content

Commit 4110448

Browse files
committed
[doc api test] Rename HttpProxy.pause to HttpProxy.resume. Update documentation and tests accordingly
1 parent 3bc7d16 commit 4110448

File tree

6 files changed

+133
-79
lines changed

6 files changed

+133
-79
lines changed

README.md

+36-14
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
4747
<pre>
4848
var http = require('http'),
4949
httpProxy = require('http-proxy');
50-
50+
//
5151
// Create your proxy server
52+
//
5253
httpProxy.createServer(9000, 'localhost').listen(8000);
5354

55+
//
5456
// Create your target server
57+
//
5558
http.createServer(function (req, res) {
5659
res.writeHead(200, {'Content-Type': 'text/plain'});
5760
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
@@ -63,11 +66,15 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
6366
<pre>
6467
var http = require('http'),
6568
httpProxy = require('http-proxy');
66-
67-
// create a proxy server with custom application logic
69+
70+
//
71+
// Create a proxy server with custom application logic
72+
//
6873
httpProxy.createServer(function (req, res, proxy) {
74+
//
6975
// Put your custom server logic here
70-
proxy.proxyRequest(9000, 'localhost');
76+
//
77+
proxy.proxyRequest(req, res, 9000, 'localhost');
7178
}).listen(8000);
7279

7380
http.createServer(function (req, res) {
@@ -81,13 +88,23 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
8188
<pre>
8289
var http = require('http'),
8390
httpProxy = require('http-proxy');
84-
85-
// create a proxy server with custom application logic
91+
92+
//
93+
// Create a proxy server with custom application logic
94+
//
8695
httpProxy.createServer(function (req, res, proxy) {
96+
//
97+
// Buffer the request so that `data` and `end` events
98+
// are not lost during async operation(s).
99+
//
100+
var buffer = proxy.buffer(req);
101+
102+
//
87103
// Wait for two seconds then respond: this simulates
88104
// performing async actions before proxying a request
105+
//
89106
setTimeout(function () {
90-
proxy.proxyRequest(9000, 'localhost');
107+
proxy.proxyRequest(req, res, 9000, 'localhost', buffer);
91108
}, 2000);
92109
}).listen(8000);
93110

@@ -102,15 +119,20 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
102119
<pre>
103120
var http = require('http'),
104121
httpProxy = require('http-proxy');
105-
106-
// create a regular http server and proxy its handler
122+
123+
//
124+
// Create a new instance of HttProxy to use in your server
125+
//
126+
var proxy = new httpProxy.HttpProxy();
127+
128+
//
129+
// Create a regular http server and proxy its handler
130+
//
107131
http.createServer(function (req, res) {
108-
// Create a new instance of HttProxy for this request
109-
// each instance is only valid for serving one request
110-
var proxy = new httpProxy.HttpProxy(req, res);
111-
132+
//
112133
// Put your custom server logic here, then proxy
113-
proxy.proxyRequest(9000, 'localhost', req, res);
134+
//
135+
proxy.proxyRequest(req, res, 9000, 'localhost');
114136
}).listen(8001);
115137

116138
http.createServer(function (req, res) {

bin/node-http-proxy

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var path = require('path'),
99
var help = [
1010
"usage: node-http-proxy [options] ",
1111
"",
12-
"All options should be set with the syntax --option=value",
12+
"Starts a node-http-proxy server using the specified command-line options",
1313
"",
1414
"options:",
1515
" --port PORT Port that the proxy server should run on",
@@ -20,8 +20,7 @@ var help = [
2020
].join('\n');
2121

2222
if (argv.h || argv.help || Object.keys(argv).length === 2) {
23-
util.puts(help);
24-
process.exit(0);
23+
return util.puts(help);
2524
}
2625

2726
var location, config = {},

demo.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue +
5959
// Http Proxy Server with Latency
6060
//
6161
httpProxy.createServer(function (req, res, proxy) {
62-
var paused = proxy.pause(req);
62+
var buffer = proxy.buffer(req);
6363
setTimeout(function() {
64-
proxy.proxyRequest(req, res, 9000, 'localhost', paused);
64+
proxy.proxyRequest(req, res, 9000, 'localhost', buffer);
6565
}, 200)
6666
}).listen(8002);
6767
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline);
@@ -82,9 +82,9 @@ util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue +
8282
//
8383
var standAloneProxy = new httpProxy.HttpProxy();
8484
http.createServer(function (req, res) {
85-
var paused = standAloneProxy.pause(req);
85+
var buffer = standAloneProxy.buffer(req);
8686
setTimeout(function() {
87-
proxy.proxyRequest(req, res, 9000, 'localhost', paused);
87+
proxy.proxyRequest(req, res, 9000, 'localhost', buffer);
8888
}, 200);
8989
}).listen(8004);
9090
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);

0 commit comments

Comments
 (0)