From faf2618cf3b53a972779514842bc4264ec9541fa Mon Sep 17 00:00:00 2001 From: indexzero Date: Wed, 18 May 2011 21:06:21 -0400 Subject: [PATCH] [doc] Update docco docs --- docs/balancing-proxy.html | 90 +++++++++++++++++++++++++++++++++++++++ docs/node-http-proxy.html | 23 ++++++---- docs/proxy-table.html | 4 +- 3 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 docs/balancing-proxy.html diff --git a/docs/balancing-proxy.html b/docs/balancing-proxy.html new file mode 100644 index 000000000..ba3256e14 --- /dev/null +++ b/docs/balancing-proxy.html @@ -0,0 +1,90 @@ + balancing-proxy.js

balancing-proxy.js

/*
+  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.
+
+*/
+
+var net = require('net'),
+    HTTPParser = process.binding('http_parser').HTTPParser,
+    streams = require('morestreams');
+
+exports.createServer = function () {
+  var args = Array.prototype.slice.call(arguments), 
+      callback = typeof args[0] === 'function' && args.shift(),
+      options = {}, port, host, server;
+      
+  server = net.createServer(function (socket) {
+    var buffer = new streams.BufferedStream(),
+        parser = new HTTPParser('request');
+    
+    parser.onHeaderField = function(b, start, len) {
+      var slice = 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) {
+      var slice = 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) {
+      var ret = parser.execute(d, start, end - start);
+      console.log(ret);
+    };
+    
+    socket.onend = function() {
+      var ret = parser.finish();
+
+      if (ret instanceof Error) {
+        socket.destroy(ret);
+        return;
+      }
+
+      if (socket.writable) {
+        socket.end();
+      }
+    };
+    
+    socket.write('hello world');
+    socket.end();
+  });
+  
+  return server;
+};
+
+
\ No newline at end of file diff --git a/docs/node-http-proxy.html b/docs/node-http-proxy.html index 9e5a61f9c..72681017a 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

/*
+      node-http-proxy.js           

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 @@ 

@handler {function} Optional Request handler for the server

exports.createServer = function () {
   var args = Array.prototype.slice.call(arguments), 
       callback = typeof args[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 @@ 

@options {Object} Options for this instance.

var self = 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 {Object} Options for the outgoing proxy request.

options.https {Object|boolean} Settings for https.
HttpProxy.prototype.proxyRequest = function (req, res, options) {
   var self = this, errState = false, location, outgoing, protocol, reverseProxy;
-  

Create an empty options hash if none is passed.

  options = options || {};
+  

Create an empty options hash if none is passed. +If default options have been passed to the constructor +of this instance, use them by default.

  options      = options || {};
+  options.host = options.host || this.target.host;
+  options.port = options.port || this.target.port;
   

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 @@

@err {Error} Error contacting the proxy target

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 @@

@err {Error} Error contacting the proxy target

Force the connection header to be 'close' until node.js core re-implements 'keep-alive'.

  outgoing.headers['connection'] = 'close';
   
-  protocol = _getProtocol(options.https || this.https, outgoing);
+  protocol = _getProtocol(options.https || this.target.https, outgoing);
   

Open new HTTP request to internal resource with will act as a reverse proxy pass

  reverseProxy = protocol.request(outgoing, function (response) {
     

Process the reverseProxy response when it's received.

    if (response.headers.connection) {
       if (req.headers.connection) response.headers.connection = req.headers.connection;
@@ -443,8 +448,8 @@ 

@req {ServerRequest} Incoming HTTP Request to proxy.

detach(); }); };

Client socket

  _socket(socket);
-  

Remote host address

  var protocolName = options.https || this.https ? 'https' : 'http',
-      agent        = _getAgent(options.host, options.port, options.https || this.https),
+  

Remote host address

  var protocolName = options.https || this.target.https ? 'https' : 'http',
+      agent        = _getAgent(options.host, options.port, options.https || this.target.https),
       remoteHost   = options.host + (options.port - 80 === 0 ? '' : ':' + options.port);

Change headers

  if (this.changeOrigin) {
     req.headers.host   = remoteHost;
     req.headers.origin = protocolName + '://' + remoteHost;
diff --git a/docs/proxy-table.html b/docs/proxy-table.html
index d03364740..dac6eeae7 100644
--- a/docs/proxy-table.html
+++ b/docs/proxy-table.html
@@ -1,5 +1,5 @@
-      proxy-table.js           

proxy-table.js

/*
-  node-http-proxy.js: Lookup table for proxy targets in node.js
+      proxy-table.js           

proxy-table.js

/*
+  proxy-table.js: Lookup table for proxy targets in node.js
 
   Copyright (c) 2010 Charlie Robbins