Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix-ws-upgrade'
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed Feb 21, 2014
2 parents 608e526 + d138c56 commit 64afd01
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -37,7 +37,6 @@ Usage
-s, --service <name[@version]> amino service to proxy to, with optional semver (default: app)
-t, --threads <num> number of threads to use (default: CPU count)
-r, --redis <port/host/host:port/list> redis server(s) used by amino service (can be comma-separated)
--sockets <num> number of concurrent sockets to allow (default: 25000)
--stickyQuery <name> name of a GET variable to base sticky sessions on
--stickyIp enable sticky sessions based on remote IP address
--stickyCookie <cookie name> name of a cookie to base sticky sessions on
Expand Down
1 change: 0 additions & 1 deletion bin/amino-gateway
Expand Up @@ -14,7 +14,6 @@ var program = require('commander')
.option('-s, --service <name[@version]>', 'amino service to proxy to, with optional semver (default: app)', 'app')
.option('-t, --threads <num>', 'number of threads to use (default: CPU count)', Number, require('os').cpus().length)
.option('-r, --redis <port/host/host:port/list>', 'redis server(s) used by amino service (can be comma-separated)', list)
.option('--sockets <num>', 'number of concurrent sockets to allow (default: 25000)', Number, 25000)
.option('--stickyQuery <name>', 'name of a GET variable to base sticky sessions on')
.option('--stickyIp', 'enable sticky sessions based on remote IP address')
.option('--stickyCookie <cookie name>', 'name of a cookie to base sticky sessions on')
Expand Down
20 changes: 11 additions & 9 deletions index.js
@@ -1,5 +1,6 @@
var cookie = require('cookie')
, parseUrl = require('url').parse
, http = require('http')
, httpProxy = require('http-proxy')
, addr = require('addr')
, cluster = require('cluster')
Expand Down Expand Up @@ -85,15 +86,18 @@ exports.attach = function (options) {
}
}

if (opts.sockets) {
httpProxy.setMaxSockets(opts.sockets);
}
// No longer supported by http-proxy -- problem?
// if (opts.sockets) {
// httpProxy.setMaxSockets(opts.sockets);
// }

if (options.maintPage) {
var maintPage = require('dish').file(options.maintPage);
}

var server = httpProxy.createServer(function (req, res, proxy) {
var proxy = httpProxy.createProxyServer();

var server = http.createServer(function (req, res) {
if (options.maintMode) {
var remoteIp = addr(req);
if (options.maintIps && ~options.maintIps.indexOf(remoteIp)) doProxy();
Expand All @@ -106,27 +110,25 @@ exports.attach = function (options) {
}

function doProxy () {
var buffer = httpProxy.buffer(req);
setupRequest(req, function (spec) {
req._spec = spec;
d.run(function () {
proxy.proxyRequest(req, res, {host: spec.host, port: spec.port, buffer: buffer});
proxy.web(req, res, { target: spec });
});
});
}
});

server.on('upgrade', function (req, socket, head) {
var buffer = httpProxy.buffer(req);
setupRequest(req, function (spec) {
req._spec = spec;
d.run(function () {
server.proxy.proxyWebSocketRequest(req, socket, head, {host: spec.host, port: spec.port, buffer: buffer});
proxy.ws(req, socket, head, { target: spec });
});
});
});

server.proxy.on('proxyError', function (err, req, res) {
proxy.on('error', function (err, req, res) {
onReqError(err, req, res, req._sReq, req._spec);
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"amino": "~1.1.4",
"cookie": "~0.0.4",
"http-proxy": "~0.8.2",
"http-proxy": "~1.0.2",
"addr": "~1.0.0",
"commander": "~1.0.3",
"dish": "~0.1.0"
Expand Down

0 comments on commit 64afd01

Please sign in to comment.