/*
+ balancing-proxy.js: Transparent Load-Balancing Optimized HTTP Proxy
+
+ Copyright (c) 2011 Charlie Robbins
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+*/
+
+varnet=require('net'),
+ HTTPParser=process.binding('http_parser').HTTPParser,
+ streams=require('morestreams');
+
+exports.createServer=function(){
+ varargs=Array.prototype.slice.call(arguments),
+ callback=typeofargs[0]==='function'&&args.shift(),
+ options={},port,host,server;
+
+ server=net.createServer(function(socket){
+ varbuffer=newstreams.BufferedStream(),
+ parser=newHTTPParser('request');
+
+ parser.onHeaderField=function(b,start,len){
+ varslice=b.toString('ascii',start,start+len).toLowerCase();
+ if(parser.value!=undefined){
+ require('eyes').inspect(parser.value,parser.field);
+ parser.field=null;
+ parser.value=null;
+ }
+ if(parser.field){
+ parser.field+=slice;
+ }else{
+ parser.field=slice;
+ }
+ };
+
+ parser.onHeaderValue=function(b,start,len){
+ varslice=b.toString('ascii',start,start+len);
+ if(parser.value){
+ parser.value+=slice;
+ }else{
+ parser.value=slice;
+ }
+ };
+
+ parser.socket=socket;
+
+ socket.ondata=function(d,start,end){
+ varret=parser.execute(d,start,end-start);
+ console.log(ret);
+ };
+
+ socket.onend=function(){
+ varret=parser.finish();
+
+ if(retinstanceofError){
+ socket.destroy(ret);
+ return;
+ }
+
+ if(socket.writable){
+ socket.end();
+ }
+ };
+
+ socket.write('hello world');
+ socket.end();
+ });
+
+ returnserver;
+};
+
+
\ No newline at end of file
diff --git a/docs/node-http-proxy.html b/docs/node-http-proxy.html
index 9e5a61f..7268101 100644
--- a/docs/node-http-proxy.html
+++ b/docs/node-http-proxy.html
@@ -1,4 +1,4 @@
- node-http-proxy.js
/* node-http-proxy.js: http proxy for node.js Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Marak Squires, Fedor Indutny
@@ -99,8 +99,7 @@ made by all instances of HttpProxy
exports.createServer=function(){varargs=Array.prototype.slice.call(arguments),callback=typeofargs[0]==='function'&&args.shift(),
- options={},
- port,host,forward,silent,proxy,server;
+ options={},port,host,forward,silent,proxy,server;if(args.length>=2){port=args[0];
@@ -181,8 +180,10 @@ for managing the life-cycle of streaming reverse proxyied HTTP requests.
varself=this;options=options||{};
+ options.target=options.target||{};
+
this.forward=options.forward;
- this.https=options.https;
+ this.target=options.target;this.changeOrigin=options.changeOrigin||false;if(options.router){
@@ -253,7 +254,11 @@ options.buffer {Object} Result from `httpProxy.buffer(req)`
options.https {Object|boolean} Settings for https.
Check the proxy table for this instance to see if we need
to get the proxy location for the request supplied. We will
always ignore the proxyTable if an explicit port and host
@@ -300,7 +305,7 @@ contacting the proxy target at host / port.
outgoing={host:options.host,port:options.port,
- agent:_getAgent(options.host,options.port,options.https||this.https),
+ agent:_getAgent(options.host,options.port,options.https||this.target.https),method:req.method,path:req.url,headers:req.headers
@@ -308,7 +313,7 @@ contacting the proxy target at host / port.
Process the reverseProxyresponse when it's received.
if(response.headers.connection){if(req.headers.connection)response.headers.connection=req.headers.connection;
@@ -443,8 +448,8 @@ For client set encoding