/*
+ 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
@@ -29,7 +29,7 @@
https = require('https'),
events = require('events'),
ProxyTable = require('./proxy-table').ProxyTable,
- maxSockets = 100; |
Version 0.5.0 | exports.version = [0, 5, 0]; |
function _getAgent (host, port, secure)
+ maxSockets = 100; |
Version 0.5.3 // 5/17/2011 | exports.version = [0, 5, 3]; |
function _getAgent (host, port, secure)
@host {string} Host of the agent to get
@@ -179,10 +179,11 @@ for managing the life-cycle of streaming reverse proxyied HTTP requests.
| var HttpProxy = exports.HttpProxy = function (options) {
events.EventEmitter.call(this);
- var self = this;
- options = options || {};
- this.forward = options.forward;
- this.https = options.https;
+ var self = this;
+ options = options || {};
+ this.forward = options.forward;
+ this.https = options.https;
+ this.changeOrigin = options.changeOrigin || false;
if (options.router) {
this.proxyTable = new ProxyTable(options.router, options.silent, options.hostnameOnly);
@@ -389,7 +390,12 @@ For client set encoding |
socket.setTimeout(0);
socket.setNoDelay(true);
if (keepAlive) {
- socket.setKeepAlive(true, 0);
+ if (socket.setKeepAlive) {
+ socket.setKeepAlive(true, 0);
+ }
+ else if (socket.pair.cleartext.socket.setKeepAlive) {
+ socket.pair.cleartext.socket.setKeepAlive(true, 0);
+ }
}
else {
socket.setEncoding('utf8');
@@ -437,9 +443,12 @@ For client set encoding |
detach();
});
}; |
| Client socket | |
| Remote host address | var agent = _getAgent(options.host, options.port),
- remoteHost = options.host + (options.port - 80 === 0 ? '' : ':' + options.port); |
| Change headers | req.headers.host = remoteHost;
- req.headers.origin = 'http://' + options.host;
+ |
| Remote host address | var protocolName = options.https || this.https ? 'https' : 'http',
+ agent = _getAgent(options.host, options.port, options.https || this.https),
+ remoteHost = options.host + (options.port - 80 === 0 ? '' : ':' + options.port); |
| Change headers | if (this.changeOrigin) {
+ req.headers.host = remoteHost;
+ req.headers.origin = protocolName + '://' + remoteHost;
+ }
outgoing = {
host: options.host,
diff --git a/docs/proxy-table.html b/docs/proxy-table.html
index 3246477..d033647 100644
--- a/docs/proxy-table.html
+++ b/docs/proxy-table.html
@@ -1,4 +1,4 @@
- proxy-table.js proxy-table.js | | | | /*
+ proxy-table.js proxy-table.js | | | | /*
node-http-proxy.js: Lookup table for proxy targets in node.js
Copyright (c) 2010 Charlie Robbins
| | |