[refactor minor] s/caronte/http-proxy/ or s/caronte/httpProxy/ where appropriate.

This commit is contained in:
indexzero 2013-09-26 03:37:08 -04:00
parent f7f5fa727e
commit bb0d28c587
18 changed files with 99 additions and 95 deletions

View File

@ -2,10 +2,10 @@
<img src="doc/logo.png?raw=true"/>
</p>
Caronte
node-http-proxy
=======
Caronte is an HTTP programmable proxying library that supports
`node-http-proxy` is an HTTP programmable proxying library that supports
websockets. It is suitable for implementing components such as
proxies and load balancers.
@ -21,12 +21,12 @@ proxies and load balancers.
### Core Concept
A new proxy is created by calling `createProxyServer` and passing
an `options` object as argument ([valid properties are available here](tree/master/lib/caronte.js#L26-L39))
an `options` object as argument ([valid properties are available here](tree/master/lib/http-proxy.js#L26-L39))
```javascript
var caronte = require('caronte');
var httpProxy = require('http-proxy');
var proxy = caronte.createProxyServer(options);
var proxy = httpProxy.createProxyServer(options);
```
An object will be returned with four values:
@ -44,7 +44,7 @@ require('http').createServer(function(req, res) {
});
```
When a request is proxied it follows two different pipelines ([available here](tree/master/lib/caronte/passes))
When a request is proxied it follows two different pipelines ([available here](tree/master/lib/http-proxy/passes))
which apply transformations to both the `req` and `res` object.
The first pipeline (ingoing) is responsible for the creation and manipulation of the stream that connects your client to the target.
The second pipeline (outgoing) is responsible for the creation and manipulation of the stream that, from your target, returns data
@ -58,11 +58,11 @@ In addition, every stage emits a corresponding event so introspection during the
```js
var http = require('http'),
caronte = require('caronte');
httpProxy = require('http-proxy');
//
// Create your proxy server
//
caronte.createProxyServer({target:'http://localhost:9000'}).listen(8000);
httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000);
//
// Create your target server
@ -78,12 +78,12 @@ http.createServer(function (req, res) {
``` js
var http = require('http'),
caronte = require('caronte');
httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
var proxy = caronte.createProxyServer({});
var proxy = httpProxy.createProxyServer({});
var server = require('http').createServer(function(req, res) {
proxy.web(req, res, { target: 'http://127.0.0.1:5060' });
@ -103,7 +103,7 @@ server.listen(5050);
### Options
`caronte.createProxyServer` supports the following options:
`httpProxy.createProxyServer` supports the following options:
* **target**: url string to be parsed with the url module
* **forward**: url string to be parsed with the url module
@ -130,7 +130,7 @@ Logo created by [Diego Pasquali](http://dribbble.com/diegopq)
>The MIT License (MIT)
>
>Copyright (c) 2013 Nodejitsu Inc.
>Copyright (c) 2010 - 2013 Nodejitsu Inc.
>
>Permission is hereby granted, free of charge, to any person obtaining a copy
>of this software and associated documentation files (the "Software"), to deal

View File

@ -1,17 +1,17 @@
var caronte = require('../index');
var httpProxy = require('../index');
/*
* Create your proxy server
*/
var proxyServer = caronte.createProxyServer({target:'http://localhost:30404', ws:true});
var proxyServer = httpProxy.createProxyServer({target:'http://localhost:30404', ws:true});
// Register an error handler for web requests
proxyServer.ee.on("caronte:outgoing:web:error", function(err, req, res){
proxyServer.ee.on("http-proxy:outgoing:web:error", function(err, req, res){
res.writeHead(502);
res.end("There was an error proxying your request");
});
// Register an error handler for web-socket requests
proxyServer.ee.on("caronte:outgoing:ws:error", function(err, req, socket, head){
proxyServer.ee.on("http-proxy:outgoing:ws:error", function(err, req, socket, head){
socket.close();
});

View File

@ -1,4 +1,4 @@
var caronte = require('caronte'),
var httpProxy = require('http-proxy'),
https = require('https');
/*
* Create your proxy server pointing to a secure domain
@ -9,7 +9,7 @@ var options = {target : 'https://google.com',
headers: {host: 'google.com'}
};
var proxyServer = caronte.createProxyServer(options);
var proxyServer = httpProxy.createProxyServer(options);
console.log("Proxy server listening on port 8000");
proxyServer.listen(8000);

View File

@ -1,10 +1,10 @@
var caronte = require('caronte');
var httpProxy = require('http-proxy');
/*
* Create your proxy server pointing to a secure domain
*/
var options = {target:'https://google.com'};
var proxyServer = caronte.createProxyServer(options);
var proxyServer = httpProxy.createProxyServer(options);
console.log("Proxy server listening on port 8000");
proxyServer.listen(8000);

View File

@ -1,10 +1,10 @@
var http = require('http'),
caronte = require('caronte');
httpProxy = require('http-proxy');
//
// Create your proxy server
//
console.log("Proxy server listening on port 8000");
caronte.createProxyServer({target:'http://localhost:9000'}).listen(8000);
httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000);
//
// Create your target server

View File

@ -10,4 +10,4 @@
* Dante - The Divine Comedy (Canto III)
*/
module.exports = require('./lib/caronte');
module.exports = require('./lib/http-proxy');

View File

@ -1,16 +1,16 @@
var http = require('http'),
https = require('https'),
url = require('url'),
caronte = require('./caronte/'),
events = require('eventemitter2'),
proxy = exports;
var http = require('http'),
https = require('https'),
url = require('url'),
httpProxy = require('./http-proxy'),
events = require('eventemitter2'),
proxy = exports;
/**
* Creates the proxy server.
*
* Examples:
*
* caronte.createProxyServer({ .. }, 8000)
* httpProxy.createProxyServer({ .. }, 8000)
* // => '{ web: [Function], ws: [Function] ... }'
*
* @param {Object} Options Config object passed to the proxy
@ -20,7 +20,7 @@ var http = require('http'),
* @api public
*/
proxy.createProxyServer = function createProxyServer(options) {
proxy.createProxyServer = proxy.createServer = function createProxyServer(options) {
if(!options) {
throw new Error([
"`options` is needed and it must have the following layout:",
@ -44,8 +44,8 @@ proxy.createProxyServer = function createProxyServer(options) {
return {
ee : options.ee,
web : caronte.createWebProxy(options),
ws : caronte.createWsProxy(options),
web : httpProxy.createWebProxy(options),
ws : httpProxy.createWsProxy(options),
listen : function listen(port) {
var server = options.ssl ? https.createServer(options.ssl, this.web) : http.createServer(this.web);

View File

@ -1,11 +1,11 @@
var caronte = exports,
extend = require('util')._extend,
var httpProxy = exports,
extend = require('util')._extend,
parse_url = require('url').parse,
web = require('./passes/web-incoming'),
ws = require('./passes/ws-incoming');
web = require('./passes/web-incoming'),
ws = require('./passes/ws-incoming');
caronte.createWebProxy = createRightProxy('web');
caronte.createWsProxy = createRightProxy('ws');
httpProxy.createWebProxy = createRightProxy('web');
httpProxy.createWsProxy = createRightProxy('ws');
/**
* Returns a function that creates the loader for
@ -13,7 +13,7 @@ caronte.createWsProxy = createRightProxy('ws');
*
* Examples:
*
* caronte.createRightProxy('ws')
* httpProxy.createRightProxy('ws')
* // => [Function]
*
* @param {String} Type Either 'ws' or 'web'
@ -36,7 +36,7 @@ function createRightProxy(type) {
var self = this,
args = [].slice.call(arguments),
cntr = args.length - 1,
ev = 'caronte:' + type + ':incoming:',
ev = 'http-proxy:' + type + ':incoming:',
head;
if(

View File

@ -106,7 +106,7 @@ web_o = Object.keys(web_o).map(function(pass) {
// Error Handler
proxyReq.on('error', function(err){
var ev = 'caronte:outgoing:web:';
var ev = 'http-proxy:outgoing:web:';
// If no error listeners, so throw the error.
if (!options.ee.listeners(ev + 'error').length){
throw err;
@ -118,7 +118,7 @@ web_o = Object.keys(web_o).map(function(pass) {
req.pipe(proxyReq);
proxyReq.on('response', function(proxyRes) {
var ev = 'caronte:outgoing:web:';
var ev = 'http-proxy:outgoing:web:';
options.ee.emit(ev + 'begin', req, res);

View File

@ -107,7 +107,7 @@ var passes = exports;
);
// Error Handler
proxyReq.on('error', function(err){
var ev = 'caronte:outgoing:ws:';
var ev = 'http-proxy:outgoing:ws:';
// If no error listeners, so throw the error.
if (!options.ee.listeners(ev + 'error').length){
throw err;

View File

@ -1,9 +1,13 @@
{
"name" : "caronte",
"version" : "0.0.0",
"name" : "http-proxy",
"version" : "1.0.0",
"description" : "HTTP proxying for the masses",
"author" : "yawnt <yawn.localhost@gmail.com>",
"author": "Nodejitsu Inc. <info@nodejitsu.com>",
"maintainers" : [
"yawnt <yawnt@nodejitsu.com>",
"indexzero <charlie@nodejitsu.com>"
],
"main" : "index.js",
"dependencies" : {
@ -24,7 +28,7 @@
},
"scripts" : {
"coveralls" : "mocha --require blanket --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js",
"blanket" : { "pattern": "lib/caronte" },
"blanket" : { "pattern": "lib/http-proxy" },
"test" : "./node_modules/.bin/mocha -R landing test/*-test.js",
"test-cov" : "./node_modules/.bin/mocha --require blanket -R html-cov > cov/coverage.html"
},

View File

@ -1,7 +1,7 @@
var common = require('../lib/caronte/common'),
var common = require('../lib/http-proxy/common'),
expect = require('expect.js');
describe('lib/caronte/common.js', function () {
describe('lib/http-proxy/common.js', function () {
describe('#setupOutgoing', function () {
it('should setup the correct headers', function () {
var outgoing = {};

View File

@ -1,14 +1,14 @@
var caronte = require('../lib/caronte/passes/web-incoming'),
var httpProxy = require('../lib/http-proxy/passes/web-incoming'),
expect = require('expect.js');
describe('lib/caronte/passes/web.js', function() {
describe('lib/http-proxy/passes/web.js', function() {
describe('#deleteLength', function() {
it('should change `content-length`', function() {
var stubRequest = {
method: 'DELETE',
headers: {}
};
caronte.deleteLength(stubRequest, {}, {});
httpProxy.deleteLength(stubRequest, {}, {});
expect(stubRequest.headers['content-length']).to.eql('0');
})
});
@ -21,7 +21,7 @@ describe('lib/caronte/passes/web.js', function() {
}
}
caronte.timeout(stubRequest, {}, { timeout: 5000});
httpProxy.timeout(stubRequest, {}, { timeout: 5000});
expect(done).to.eql(5000);
});
});
@ -36,7 +36,7 @@ describe('lib/caronte/passes/web.js', function() {
}
it('set the correct x-forwarded-* headers', function () {
caronte.XHeaders(stubRequest, {}, { xfwd: true });
httpProxy.XHeaders(stubRequest, {}, { xfwd: true });
expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.2');
expect(stubRequest.headers['x-forwarded-port']).to.be('8080');
expect(stubRequest.headers['x-forwarded-proto']).to.be('http');

View File

@ -1,11 +1,11 @@
var caronte = require('../lib/caronte/passes/web-outgoing'),
var httpProxy = require('../lib/http-proxy/passes/web-outgoing'),
expect = require('expect.js');
describe('lib/caronte/passes/web-outgoing.js', function () {
describe('lib/http-proxy/passes/web-outgoing.js', function () {
describe('#setConnection', function () {
it('set the right connection with 1.0 - `close`', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpProxy.setConnection({
httpVersion: '1.0',
headers: {
connection: null
@ -17,7 +17,7 @@ describe('lib/caronte/passes/web-outgoing.js', function () {
it('set the right connection with 1.0 - req.connection', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpProxy.setConnection({
httpVersion: '1.0',
headers: {
connection: 'hey'
@ -29,7 +29,7 @@ describe('lib/caronte/passes/web-outgoing.js', function () {
it('set the right connection - req.connection', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpProxy.setConnection({
httpVersion: null,
headers: {
connection: 'hola'
@ -41,7 +41,7 @@ describe('lib/caronte/passes/web-outgoing.js', function () {
it('set the right connection - `keep-alive`', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpProxy.setConnection({
httpVersion: null,
headers: {
connection: null
@ -61,7 +61,7 @@ describe('lib/caronte/passes/web-outgoing.js', function () {
}
}
caronte.writeStatusCode({}, res, { statusCode: 200 });
httpProxy.writeStatusCode({}, res, { statusCode: 200 });
});
});
@ -80,7 +80,7 @@ describe('lib/caronte/passes/web-outgoing.js', function () {
headers: {}
};
caronte.writeHeaders({}, res, proxyRes);
httpProxy.writeHeaders({}, res, proxyRes);
expect(res.headers.hey).to.eql('hello');
expect(res.headers.how).to.eql('are you?');
@ -95,7 +95,7 @@ describe('lib/caronte/passes/web-outgoing.js', function () {
};
caronte.removeChunked({ httpVersion: '1.0' }, {}, proxyRes);
httpProxy.removeChunked({ httpVersion: '1.0' }, {}, proxyRes);
expect(proxyRes.headers['transfer-encoding']).to.eql(undefined);
});

View File

@ -1,7 +1,7 @@
var caronte = require('../lib/caronte/passes/ws-incoming'),
var httpProxy = require('../lib/http-proxy/passes/ws-incoming'),
expect = require('expect.js');
describe('lib/caronte/passes/ws-incoming.js', function () {
describe('lib/http-proxy/passes/ws-incoming.js', function () {
describe('#checkMethodAndHeader', function () {
it('should drop non-GET connections', function () {
var destroyCalled = false,
@ -15,7 +15,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
destroyCalled = true;
}
}
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
returnValue = httpProxy.checkMethodAndHeader(stubRequest, stubSocket);
expect(returnValue).to.be(true);
expect(destroyCalled).to.be(true);
})
@ -32,7 +32,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
destroyCalled = true;
}
}
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
returnValue = httpProxy.checkMethodAndHeader(stubRequest, stubSocket);
expect(returnValue).to.be(true);
expect(destroyCalled).to.be(true);
})
@ -51,7 +51,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
destroyCalled = true;
}
}
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
returnValue = httpProxy.checkMethodAndHeader(stubRequest, stubSocket);
expect(returnValue).to.be(true);
expect(destroyCalled).to.be(true);
})
@ -70,7 +70,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
destroyCalled = true;
}
}
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
returnValue = httpProxy.checkMethodAndHeader(stubRequest, stubSocket);
expect(returnValue).to.be(undefined);
expect(destroyCalled).to.be(false);
})
@ -97,7 +97,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
nodelay: false,
keepalive: false
},
returnValue = caronte.setupSocket({}, stubSocket);
returnValue = httpProxy.setupSocket({}, stubSocket);
expect(returnValue).to.be(undefined);
expect(socketConfig.timeout).to.eql(0);
expect(socketConfig.nodelay).to.eql(true);
@ -107,7 +107,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
describe('#XHeaders', function () {
it('return if no forward request', function () {
var returnValue = caronte.XHeaders({}, {}, {});
var returnValue = httpProxy.XHeaders({}, {}, {});
expect(returnValue).to.be(undefined);
});
@ -119,7 +119,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
},
headers: {}
}
caronte.XHeaders(stubRequest, {}, { xfwd: true });
httpProxy.XHeaders(stubRequest, {}, { xfwd: true });
expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.2');
expect(stubRequest.headers['x-forwarded-port']).to.be('8080');
expect(stubRequest.headers['x-forwarded-proto']).to.be('ws');
@ -136,7 +136,7 @@ describe('lib/caronte/passes/ws-incoming.js', function () {
},
headers: {}
};
caronte.XHeaders(stubRequest, {}, { xfwd: true });
httpProxy.XHeaders(stubRequest, {}, { xfwd: true });
expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.3');
expect(stubRequest.headers['x-forwarded-port']).to.be('8181');
expect(stubRequest.headers['x-forwarded-proto']).to.be('wss');

View File

@ -1,17 +1,17 @@
var caronte = require('../lib/caronte'),
expect = require('expect.js'),
http = require('http'),
ws = require('ws')
io = require('socket.io'),
ioClient = require('socket.io-client');
var httpProxy = require('../lib/http-proxy'),
expect = require('expect.js'),
http = require('http'),
ws = require('ws')
io = require('socket.io'),
ioClient = require('socket.io-client');
describe('lib/caronte.js', function() {
describe('lib/http-proxy.js', function() {
describe('#createProxyServer', function() {
it('should throw without options', function() {
var error;
try {
caronte.createProxyServer();
httpProxy.createProxyServer();
} catch(e) {
error = e;
}
@ -20,7 +20,7 @@ describe('lib/caronte.js', function() {
})
it('should return an object otherwise', function() {
var obj = caronte.createProxyServer({
var obj = httpProxy.createProxyServer({
target: 'http://www.google.com:80'
});
@ -32,7 +32,7 @@ describe('lib/caronte.js', function() {
describe('#createProxyServer with forward options and using web-incoming passes', function () {
it('should pipe the request using web-incoming#stream method', function (done) {
var proxy = caronte.createProxyServer({
var proxy = httpProxy.createProxyServer({
forward: 'http://127.0.0.1:8080'
}).listen('8081')
@ -52,7 +52,7 @@ describe('lib/caronte.js', function() {
describe('#createProxyServer using the web-incoming passes', function () {
it('should make the request on pipe and finish it', function(done) {
var proxy = caronte.createProxyServer({
var proxy = httpProxy.createProxyServer({
target: 'http://127.0.0.1:8080'
}).listen('8081');
@ -80,7 +80,7 @@ describe('lib/caronte.js', function() {
describe('#createProxyServer using the web-incoming passes', function () {
it('should make the request, handle response and finish it', function(done) {
var proxy = caronte.createProxyServer({
var proxy = httpProxy.createProxyServer({
target: 'http://127.0.0.1:8080'
}).listen('8081');
@ -115,11 +115,11 @@ describe('lib/caronte.js', function() {
describe('#createProxyServer() method with error response', function () {
it('should make the request and emit the error event', function(done) {
var proxy = caronte.createProxyServer({
var proxy = httpProxy.createProxyServer({
target: 'http://127.0.0.1:8080'
});
proxy.ee.on('caronte:outgoing:web:error', function (err) {
proxy.ee.on('http-proxy:outgoing:web:error', function (err) {
expect(err).to.be.an(Error);
expect(err.code).to.be('ECONNREFUSED');
proxyServer.close();
@ -138,7 +138,7 @@ describe('lib/caronte.js', function() {
describe('#createProxyServer using the web-incoming passes', function () {
it('should emit events correclty', function(done) {
var proxy = caronte.createProxyServer({
var proxy = httpProxy.createProxyServer({
target: 'http://127.0.0.1:8080'
}),
@ -155,7 +155,7 @@ describe('lib/caronte.js', function() {
source.listen('8080');
proxy.ee.on('caronte:**', function (uno, dos, tres) {
proxy.ee.on('http-proxy:**', function (uno, dos, tres) {
events.push(this.event);
})
@ -171,8 +171,8 @@ describe('lib/caronte.js', function() {
});
res.on('end', function () {
expect(events).to.contain('caronte:outgoing:web:begin');
expect(events).to.contain('caronte:outgoing:web:end');
expect(events).to.contain('http-proxy:outgoing:web:begin');
expect(events).to.contain('http-proxy:outgoing:web:end');
source.close();
proxyServer.close();
done();
@ -183,7 +183,7 @@ describe('lib/caronte.js', function() {
describe('#createProxyServer using the ws-incoming passes', function () {
it('should proxy the websockets stream', function (done) {
var proxy = caronte.createProxyServer({
var proxy = httpProxy.createProxyServer({
target: 'ws://127.0.0.1:8080',
ws: true
}),
@ -215,7 +215,7 @@ describe('lib/caronte.js', function() {
describe('#createProxyServer using the ws-incoming passes', function () {
it('should proxy a socket.io stream', function (done) {
var proxy = caronte.createProxyServer({
var proxy = httpProxy.createProxyServer({
target: 'ws://127.0.0.1:8080',
ws: true
}),