Commit 3fd3c96f authored by indexzero's avatar indexzero

[api] Force connection header to be `close` until keep-alive is replemented

parent 35886878
......@@ -242,7 +242,7 @@ HttpProxy.prototype.close = function () {
// #### @buffer {Object} **Optional** Result from `httpProxy.buffer(req)`
//
HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
var self = this, reverseProxy, location, errState = false;
var self = this, reverseProxy, location, errState = false, opts;
//
// Check the proxy table for this instance to see if we need
......@@ -301,15 +301,21 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
res.end();
}
// Open new HTTP request to internal resource with will act as a reverse proxy pass
reverseProxy = http.request({
var opts = {
host: host,
port: port,
agent: _getAgent(host, port),
method: req.method,
path: req.url,
headers: req.headers
}, function (response) {
};
// Force the `connection` header to be 'close' until
// node.js core re-implements 'keep-alive'.
opts.headers['connection'] = 'close';
// Open new HTTP request to internal resource with will act as a reverse proxy pass
reverseProxy = http.request(opts, function (response) {
// Process the `reverseProxy` `response` when it's received.
if (response.headers.connection) {
......@@ -362,17 +368,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
// request unless we have entered an error state.
//
req.on('end', function () {
//
// __Remark__ *(indexzero | 3/10/2011)*: This is a short-term workaround for a suspect error from net.js when
// `http.ClientRequest.end()` is called in reproducable, but uninvestigated scenarios
//
// net.js:313
// throw new Error('Socket.end() called already; cannot write.');
// ^
// Error: Socket.end() called already; cannot write.
// at Socket.write (net.js:313:13)
//
if (!errState && (!reverseProxy.socket || reverseProxy.socket._writeQueueLast() !== 42)) {
if (!errState) {
reverseProxy.end();
}
});
......@@ -390,20 +386,26 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
// by `this.options.forward` ignoring errors and the subsequent response.
//
HttpProxy.prototype._forwardRequest = function (req) {
var self = this, port, host, forwardProxy;
var self = this, port, host, forwardProxy, opts;
port = this.options.forward.port;
host = this.options.forward.host;
// Open new HTTP request to internal resource with will act as a reverse proxy pass
forwardProxy = http.request({
opts = {
host: host,
port: port,
agent: _getAgent(host, port),
method: req.method,
path: req.url,
headers: req.headers
}, function (response) {
};
// Force the `connection` header to be 'close' until
// node.js core re-implements 'keep-alive'.
opts.headers['connection'] = 'close';
// Open new HTTP request to internal resource with will act as a reverse proxy pass
forwardProxy = http.request(opts, function (response) {
//
// Ignore the response from the forward proxy since this is a 'fire-and-forget' proxy.
// Remark (indexzero): We will eventually emit a 'forward' event here for performance tuning.
......@@ -415,7 +417,7 @@ HttpProxy.prototype._forwardRequest = function (req) {
// Remark: Ignoring this error in the event
// forward target doesn't exist.
//
forwardProxy.on('error', function (err) { });
forwardProxy.once('error', function (err) { });
// Chunk the client request body as chunks from the proxied request come in
req.on('data', function (chunk) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment