Skip to content

Commit

Permalink
[refactor minor] s/caronte/http-proxy/ or s/caronte/httpProxy/ where …
Browse files Browse the repository at this point in the history
…appropriate.
  • Loading branch information
indexzero committed Sep 26, 2013
1 parent f7f5fa7 commit bb0d28c
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 95 deletions.
24 changes: 12 additions & 12 deletions README.md
Expand Up @@ -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.

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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' });
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/error-handling.js
@@ -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();
});

Expand Down
4 changes: 2 additions & 2 deletions examples/https-secure.js
@@ -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
Expand All @@ -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);

4 changes: 2 additions & 2 deletions examples/https.js
@@ -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);

4 changes: 2 additions & 2 deletions examples/stand-alone.js
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -10,4 +10,4 @@
* Dante - The Divine Comedy (Canto III)
*/

module.exports = require('./lib/caronte');
module.exports = require('./lib/http-proxy');
20 changes: 10 additions & 10 deletions lib/caronte.js → lib/http-proxy.js
@@ -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
Expand All @@ -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:",
Expand All @@ -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);

Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions lib/caronte/index.js → lib/http-proxy/index.js
@@ -1,19 +1,19 @@
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
* either `ws` or `web`'s passes.
*
* Examples:
*
* caronte.createRightProxy('ws')
* httpProxy.createRightProxy('ws')
* // => [Function]
*
* @param {String} Type Either 'ws' or 'web'
Expand All @@ -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(
Expand Down
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
File renamed without changes.
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions package.json
@@ -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" : {
Expand All @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions test/lib-caronte-common-test.js
@@ -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 = {};
Expand Down
10 changes: 5 additions & 5 deletions test/lib-caronte-passes-web-incoming-test.js
@@ -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');
})
});
Expand All @@ -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);
});
});
Expand All @@ -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');
Expand Down

0 comments on commit bb0d28c

Please sign in to comment.