Skip to content
Permalink
Browse files

[refactor] clean up

  • Loading branch information...
yawnt committed Jun 12, 2013
1 parent 27d2359 commit 5b570e121553acd639904e053128d1692822de08
Showing with 18 additions and 30 deletions.
  1. +17 −18 lib/node-http-proxy/http-proxy.js
  2. +1 −12 lib/node-http-proxy/proxy-stream.js
@@ -155,6 +155,18 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
req.pipe(new ForwardStream(options.forward));
}

//
// Handle 'error' events from the `req` (e.g. `Parse Error`).
//
req.on('error', proxyError);

//Aborts pReq if client aborts the connection.
req.on('close', function () {
if (!errState) {
pReq.abort();
}
});

//
// #### function proxyError (err)
// #### @err {Error} Error contacting the proxy target
@@ -179,27 +191,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
// This NODE_ENV=production behavior is mimics Express and
// Connect.
//
if (process.env.NODE_ENV === 'production') {
res.write('Internal Server Error');
}
else {
res.write('An error has occurred: ' + JSON.stringify(err));
}

res.write(process.env.NODE_ENV === 'production' ?
'Internal Server Error' :
'An error has occurred: ' + JSON.stringify(err) ;
);
}

try { res.end() }
catch (ex) { console.error('res.end error: %s', ex.message) }
}

//
// Handle 'error' events from the `req` (e.g. `Parse Error`).
//
req.on('error', proxyError);

//Aborts pReq if client aborts the connection.
req.on('close', function () {
if (!errState) {
pReq.abort();
}
});
};
@@ -86,18 +86,7 @@ ProxyStream.prototype.start = function (req) {
//
// Process the `pReq` `pRes` when it's received.
//
if (req.httpVersion === '1.0') {
if (req.headers.connection) {
pRes.headers.connection = req.headers.connection
} else {
pRes.headers.connection = 'close'
}
} else if (!pRes.headers.connection) {
if (req.headers.connection) { pRes.headers.connection = req.headers.connection }
else {
pRes.headers.connection = 'keep-alive'
}
}
pRes.headers.connection = req.headers.connection || req.httpVersion === '1.0' ? 'close' : 'keep-alive';

// Remove `Transfer-Encoding` header if client's protocol is HTTP/1.0
// or if this is a DELETE request with no content-length header.

0 comments on commit 5b570e1

Please sign in to comment.
You can’t perform that action at this time.