Skip to content

Commit

Permalink
[api] Start work on generic response code handlers for proxy response…
Browse files Browse the repository at this point in the history
…s. Lead up to handling 301/302/303/307 response codes correctly
  • Loading branch information
indexzero committed Apr 26, 2011
1 parent ddf31b2 commit 3a3336c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/node-http-proxy.js
Expand Up @@ -78,6 +78,19 @@ function _getProtocol (secure, outgoing) {
return protocol;
}

var responseHandlers = {
301: function (res, proxyRes) {
res.end();

//
// `proxyRes.statusCode === 304`: No `data` or `end`
// events so return `true` here so that we do not
// listen to them on the `proxyRes`
//
return true;
}
}

//
// ### function getMaxSockets ()
// Returns the maximum number of sockets
Expand Down Expand Up @@ -398,9 +411,15 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
// Set the headers of the client response
res.writeHead(response.statusCode, response.headers);

// `response.statusCode === 304`: No 'data' event and no 'end'
if (response.statusCode === 304) {
return res.end();
if (typeof proxyHandlers[response.statusCode] === 'function') {
//
// If there is a specific handler for this particular response code then call
// it. This allows for these handlers to be called in a modular way and also
// stop the propagation of events to the `res` if necessary.
//
if (proxyHandlers[response.statusCode](res, proxyRes) === true) {
return;
}
}

// For each data `chunk` received from the `reverseProxy`
Expand Down

0 comments on commit 3a3336c

Please sign in to comment.