Skip to content

Commit

Permalink
[merge] Merge from significant internal refactor in v0.7.x. No extern…
Browse files Browse the repository at this point in the history
…al API changes
  • Loading branch information
indexzero committed Sep 10, 2011
2 parents 38315f6 + 0182ba3 commit f7010e5
Show file tree
Hide file tree
Showing 32 changed files with 1,598 additions and 1,099 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test/config.json
config.json
node_modules/
npm-debug.log
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ 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);
var buffer = httpProxy.buffer(req);

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

### Configuring your Socket limits

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:

1. By passing the `maxSockets` option to `httpProxy.createServer()`
2. By calling `httpProxy.setMaxSockets(n)`, where `n` is the number of sockets you with to use.

## Using node-http-proxy from the command line
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:

Expand Down
2 changes: 1 addition & 1 deletion bin/node-http-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var path = require('path'),
fs = require('fs'),
util = require('util'),
argv = require('optimist').argv,
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../lib/node-http-proxy');

var help = [
"usage: node-http-proxy [options] ",
Expand Down
9 changes: 3 additions & 6 deletions examples/lib/store.js → examples/helpers/store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

module.exports = Store
//
// just to make these example a little bit interesting,
// make a little key value store with an http interface
Expand All @@ -20,12 +19,10 @@ module.exports = Store
//
// TODO: cached map-reduce views and auto-magic sharding.
//
var Store = module.exports = function Store () {
this.store = {};
};



function Store () {
this.store = {}
}
Store.prototype = {
get: function (key) {
return this.store[key]
Expand Down
21 changes: 11 additions & 10 deletions examples/basic-proxy.js → examples/http/basic-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');

// ascii art from http://github.com/marak/asciimo
var welcome = '\
# # ##### ##### ##### ##### ##### #### # # # # \n\
# # # # # # # # # # # # # # # # \n\
###### # # # # ##### # # # # # # ## # \n\
# # # # ##### ##### ##### # # ## # \n\
# # # # # # # # # # # # # \n\
# # # # # # # # #### # # # \n';
httpProxy = require('../../lib/node-http-proxy');

var welcome = [
'# # ##### ##### ##### ##### ##### #### # # # #',
'# # # # # # # # # # # # # # # # ',
'###### # # # # ##### # # # # # # ## # ',
'# # # # ##### ##### ##### # # ## # ',
'# # # # # # # # # # # # # ',
'# # # # # # # # #### # # # '
].join('\n');

util.puts(welcome.rainbow.bold);

//
Expand Down
23 changes: 12 additions & 11 deletions examples/concurrent-proxy.js → examples/http/concurrent-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

//
// Basic Http Proxy Server
Expand All @@ -42,23 +42,24 @@ httpProxy.createServer(9000, 'localhost').listen(8000);
//


var connections = []
, go
var connections = [],
go;

http.createServer(function (req, res) {

connections.push (function (){
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 + ', ')
});

process.stdout.write(connections.length + ', ');

if (connections.length > 110 || go) {
go = true
while(connections.length)
connections.shift()()
go = true;
while (connections.length) {
connections.shift()();
}
}

}).listen(9000);

util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

//
// Http Proxy Server with Latency
//
var server = httpProxy.createServer(function (req, res, proxy) {
proxy.proxyRequest(req, res, {
port: 9000,
host: 'localhost'
});
})
var server = httpProxy.createServer(9000, 'localhost');

//
// Tell the server to listen on port 8002
Expand Down
4 changes: 2 additions & 2 deletions examples/forward-proxy.js → examples/http/forward-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

//
// Setup proxy server with forwarding
Expand Down Expand Up @@ -60,4 +60,4 @@ http.createServer(function (req, res) {

util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8003 '.yellow + 'with forward proxy'.magenta.underline);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);
4 changes: 2 additions & 2 deletions examples/latent-proxy.js → examples/http/latent-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

//
// Http Proxy Server with Latency
//
httpProxy.createServer(function (req, res, proxy) {
var buffer = proxy.buffer(req);
var buffer = httpProxy.buffer(req);
setTimeout(function() {
proxy.proxyRequest(req, res, {
port: 9000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var https = require('https'),
http = require('http'),
util = require('util'),
colors = require('colors'),
httpProxy = require('./../lib/node-http-proxy'),
httpProxy = require('../../lib/node-http-proxy'),
helpers = require('./../test/helpers');

var opts = helpers.loadHttps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var https = require('https'),
http = require('http'),
util = require('util'),
colors = require('colors'),
httpProxy = require('./../lib/node-http-proxy'),
httpProxy = require('../../lib/node-http-proxy'),
helpers = require('./../test/helpers');

var opts = helpers.loadHttps();
Expand Down
2 changes: 1 addition & 1 deletion examples/proxy-table.js → examples/http/proxy-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

//
// Http Proxy Server with Proxy Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

//
// Http Server with proxyRequest Handler and Latency
//
var proxy = new httpProxy.HttpProxy();
http.createServer(function (req, res) {
var buffer = proxy.buffer(req);
var buffer = httpProxy.buffer(req);
setTimeout(function() {
proxy.proxyRequest(req, res, {
port: 9000,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

//
// Basic Http Proxy Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ http.createServer(new Store().handler()).listen(7531)
require('http-proxy').createServer(
require('connect-jsonp')(true),
'localhost', 7531
).listen(1337)
).listen(1337)
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ httpProxy.createServer(
// This is where our middlewares go, with any options desired - in this case,
// the list of routes/URLs and their destinations.
//
require('proxy-by-url')({
require('proxy-by-url')({
'/hello': { port: 9000, host: 'localhost' },
'/charlie': { port: 80, host: 'charlieistheman.com' },
'/google': { port: 80, host: 'google.com' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ httpProxy.createServer(
//
// Target Http Server (to listen for requests on 'localhost')
//
http.createServer(
function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);

// And finally, some colored startup output.
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
Expand Down
18 changes: 9 additions & 9 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "http-proxy-examples"
, "description": "packages required to run the examples"
, "version": "0.0.0"
, "dependencies": {
"connect": "1.6"
, "connect-gzip": "0.1"
, "connect-jsonp": "0.0.5"
, "connect-restreamer": "1"
, "proxy-by-url": ">= 0.0.1"
"name": "http-proxy-examples",
"description": "packages required to run the examples",
"version": "0.0.0",
"dependencies": {
"connect": "1.6",
"connect-gzip": "0.1",
"connect-jsonp": "0.0.5",
"connect-restreamer": "1",
"proxy-by-url": ">= 0.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var sys = require('sys'),
http = require('http'),
colors = require('colors'),
websocket = require('./../vendor/websocket'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

try {
var utils = require('socket.io/lib/socket.io/utils'),
Expand Down Expand Up @@ -80,7 +80,7 @@ var proxyServer = http.createServer(function (req, res) {
// WebSocket requests as well.
//
proxyServer.on('upgrade', function (req, socket, head) {
var buffer = proxy.buffer(socket);
var buffer = httpProxy.buffer(socket);

setTimeout(function () {
proxy.proxyWebSocketRequest(req, socket, head, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var sys = require('sys'),
http = require('http'),
colors = require('colors'),
websocket = require('./../vendor/websocket'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

try {
var utils = require('socket.io/lib/socket.io/utils'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var sys = require('sys'),
http = require('http'),
colors = require('colors'),
websocket = require('./../vendor/websocket'),
httpProxy = require('./../lib/node-http-proxy');
httpProxy = require('../../lib/node-http-proxy');

try {
var utils = require('socket.io/lib/socket.io/utils'),
Expand Down
Loading

0 comments on commit f7010e5

Please sign in to comment.