Skip to content

Commit f7010e5

Browse files
committed
[merge] Merge from significant internal refactor in v0.7.x. No external API changes
2 parents 38315f6 + 0182ba3 commit f7010e5

32 files changed

+1598
-1099
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
test/config.json
1+
config.json
22
node_modules/
33
npm-debug.log

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ httpProxy.createServer(function (req, res, proxy) {
114114
// Buffer the request so that `data` and `end` events
115115
// are not lost during async operation(s).
116116
//
117-
var buffer = proxy.buffer(req);
117+
var buffer = httpProxy.buffer(req);
118118

119119
//
120120
// Wait for two seconds then respond: this simulates
@@ -357,6 +357,13 @@ server.on('upgrade', function(req, socket, head) {
357357
});
358358
```
359359

360+
### Configuring your Socket limits
361+
362+
By default, `node-http-proxy` will set a 100 socket limit for all `host:port` proxy targets. If you wish to change this you can two it in two ways:
363+
364+
1. By passing the `maxSockets` option to `httpProxy.createServer()`
365+
2. By calling `httpProxy.setMaxSockets(n)`, where `n` is the number of sockets you with to use.
366+
360367
## Using node-http-proxy from the command line
361368
When you install this package with npm, a node-http-proxy binary will become available to you. Using this binary is easy with some simple options:
362369

bin/node-http-proxy

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var path = require('path'),
44
fs = require('fs'),
55
util = require('util'),
66
argv = require('optimist').argv,
7-
httpProxy = require('./../lib/node-http-proxy');
7+
httpProxy = require('../lib/node-http-proxy');
88

99
var help = [
1010
"usage: node-http-proxy [options] ",

examples/lib/store.js examples/helpers/store.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
module.exports = Store
32
//
43
// just to make these example a little bit interesting,
54
// make a little key value store with an http interface
@@ -20,12 +19,10 @@ module.exports = Store
2019
//
2120
// TODO: cached map-reduce views and auto-magic sharding.
2221
//
22+
var Store = module.exports = function Store () {
23+
this.store = {};
24+
};
2325

24-
25-
26-
function Store () {
27-
this.store = {}
28-
}
2926
Store.prototype = {
3027
get: function (key) {
3128
return this.store[key]

examples/basic-proxy.js examples/http/basic-proxy.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
31-
32-
// ascii art from http://github.com/marak/asciimo
33-
var welcome = '\
34-
# # ##### ##### ##### ##### ##### #### # # # # \n\
35-
# # # # # # # # # # # # # # # # \n\
36-
###### # # # # ##### # # # # # # ## # \n\
37-
# # # # ##### ##### ##### # # ## # \n\
38-
# # # # # # # # # # # # # \n\
39-
# # # # # # # # #### # # # \n';
30+
httpProxy = require('../../lib/node-http-proxy');
31+
32+
var welcome = [
33+
'# # ##### ##### ##### ##### ##### #### # # # #',
34+
'# # # # # # # # # # # # # # # # ',
35+
'###### # # # # ##### # # # # # # ## # ',
36+
'# # # # ##### ##### ##### # # ## # ',
37+
'# # # # # # # # # # # # # ',
38+
'# # # # # # # # #### # # # '
39+
].join('\n');
40+
4041
util.puts(welcome.rainbow.bold);
4142

4243
//

examples/concurrent-proxy.js examples/http/concurrent-proxy.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Basic Http Proxy Server
@@ -42,23 +42,24 @@ httpProxy.createServer(9000, 'localhost').listen(8000);
4242
//
4343

4444

45-
var connections = []
46-
, go
45+
var connections = [],
46+
go;
4747

4848
http.createServer(function (req, res) {
49-
50-
connections.push (function (){
49+
connections.push(function () {
5150
res.writeHead(200, { 'Content-Type': 'text/plain' });
5251
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
5352
res.end();
54-
})
55-
process.stdout.write(connections.length + ', ')
53+
});
54+
55+
process.stdout.write(connections.length + ', ');
56+
5657
if (connections.length > 110 || go) {
57-
go = true
58-
while(connections.length)
59-
connections.shift()()
58+
go = true;
59+
while (connections.length) {
60+
connections.shift()();
61+
}
6062
}
61-
6263
}).listen(9000);
6364

6465
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);

examples/custom-proxy-error.js examples/http/custom-proxy-error.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,12 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Proxy Server with Latency
3434
//
35-
var server = httpProxy.createServer(function (req, res, proxy) {
36-
proxy.proxyRequest(req, res, {
37-
port: 9000,
38-
host: 'localhost'
39-
});
40-
})
35+
var server = httpProxy.createServer(9000, 'localhost');
4136

4237
//
4338
// Tell the server to listen on port 8002

examples/forward-proxy.js examples/http/forward-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Setup proxy server with forwarding
@@ -60,4 +60,4 @@ http.createServer(function (req, res) {
6060

6161
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8003 '.yellow + 'with forward proxy'.magenta.underline);
6262
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
63-
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);
63+
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);

examples/latent-proxy.js examples/http/latent-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Proxy Server with Latency
3434
//
3535
httpProxy.createServer(function (req, res, proxy) {
36-
var buffer = proxy.buffer(req);
36+
var buffer = httpProxy.buffer(req);
3737
setTimeout(function() {
3838
proxy.proxyRequest(req, res, {
3939
port: 9000,

examples/proxy-https-to-http.js examples/http/proxy-https-to-http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var https = require('https'),
2828
http = require('http'),
2929
util = require('util'),
3030
colors = require('colors'),
31-
httpProxy = require('./../lib/node-http-proxy'),
31+
httpProxy = require('../../lib/node-http-proxy'),
3232
helpers = require('./../test/helpers');
3333

3434
var opts = helpers.loadHttps();

examples/proxy-https-to-https.js examples/http/proxy-https-to-https.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var https = require('https'),
2828
http = require('http'),
2929
util = require('util'),
3030
colors = require('colors'),
31-
httpProxy = require('./../lib/node-http-proxy'),
31+
httpProxy = require('../../lib/node-http-proxy'),
3232
helpers = require('./../test/helpers');
3333

3434
var opts = helpers.loadHttps();

examples/proxy-table.js examples/http/proxy-table.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Proxy Server with Proxy Table

examples/standalone-proxy.js examples/http/standalone-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Http Server with proxyRequest Handler and Latency
3434
//
3535
var proxy = new httpProxy.HttpProxy();
3636
http.createServer(function (req, res) {
37-
var buffer = proxy.buffer(req);
37+
var buffer = httpProxy.buffer(req);
3838
setTimeout(function() {
3939
proxy.proxyRequest(req, res, {
4040
port: 9000,

examples/gzip-middleware.js examples/middleware/gzip-middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
colors = require('colors'),
2929
http = require('http'),
30-
httpProxy = require('./../lib/node-http-proxy');
30+
httpProxy = require('../../lib/node-http-proxy');
3131

3232
//
3333
// Basic Http Proxy Server

examples/jsonp-middleware.js examples/middleware/jsonp-middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ http.createServer(new Store().handler()).listen(7531)
2727
require('http-proxy').createServer(
2828
require('connect-jsonp')(true),
2929
'localhost', 7531
30-
).listen(1337)
30+
).listen(1337)

examples/url-middleware.js examples/middleware/url-middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ httpProxy.createServer(
3737
// This is where our middlewares go, with any options desired - in this case,
3838
// the list of routes/URLs and their destinations.
3939
//
40-
require('proxy-by-url')({
40+
require('proxy-by-url')({
4141
'/hello': { port: 9000, host: 'localhost' },
4242
'/charlie': { port: 80, host: 'charlieistheman.com' },
4343
'/google': { port: 80, host: 'google.com' }

examples/url-middleware2.js examples/middleware/url-middleware2.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ httpProxy.createServer(
1919
//
2020
// Target Http Server (to listen for requests on 'localhost')
2121
//
22-
http.createServer(
23-
function (req, res) {
24-
res.writeHead(200, { 'Content-Type': 'text/plain' });
25-
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
26-
res.end();
27-
}).listen(9000);
22+
http.createServer(function (req, res) {
23+
res.writeHead(200, { 'Content-Type': 'text/plain' });
24+
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
25+
res.end();
26+
}).listen(9000);
2827

2928
// And finally, some colored startup output.
3029
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);

examples/package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "http-proxy-examples"
3-
, "description": "packages required to run the examples"
4-
, "version": "0.0.0"
5-
, "dependencies": {
6-
"connect": "1.6"
7-
, "connect-gzip": "0.1"
8-
, "connect-jsonp": "0.0.5"
9-
, "connect-restreamer": "1"
10-
, "proxy-by-url": ">= 0.0.1"
2+
"name": "http-proxy-examples",
3+
"description": "packages required to run the examples",
4+
"version": "0.0.0",
5+
"dependencies": {
6+
"connect": "1.6",
7+
"connect-gzip": "0.1",
8+
"connect-jsonp": "0.0.5",
9+
"connect-restreamer": "1",
10+
"proxy-by-url": ">= 0.0.1"
1111
}
1212
}

examples/latent-websocket-proxy.js examples/websocket/latent-websocket-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
3030
websocket = require('./../vendor/websocket'),
31-
httpProxy = require('./../lib/node-http-proxy');
31+
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
3434
var utils = require('socket.io/lib/socket.io/utils'),
@@ -80,7 +80,7 @@ var proxyServer = http.createServer(function (req, res) {
8080
// WebSocket requests as well.
8181
//
8282
proxyServer.on('upgrade', function (req, socket, head) {
83-
var buffer = proxy.buffer(socket);
83+
var buffer = httpProxy.buffer(socket);
8484

8585
setTimeout(function () {
8686
proxy.proxyWebSocketRequest(req, socket, head, {

examples/standalone-websocket-proxy.js examples/websocket/standalone-websocket-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
3030
websocket = require('./../vendor/websocket'),
31-
httpProxy = require('./../lib/node-http-proxy');
31+
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
3434
var utils = require('socket.io/lib/socket.io/utils'),

examples/web-socket-proxy.js examples/websocket/websocket-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var sys = require('sys'),
2828
http = require('http'),
2929
colors = require('colors'),
3030
websocket = require('./../vendor/websocket'),
31-
httpProxy = require('./../lib/node-http-proxy');
31+
httpProxy = require('../../lib/node-http-proxy');
3232

3333
try {
3434
var utils = require('socket.io/lib/socket.io/utils'),

0 commit comments

Comments
 (0)