Permalink
Browse files

[api] Start work on generic response code handlers for proxy response…

…s. Lead up to handling 301/302/303/307 response codes correctly
  • Loading branch information...
1 parent ddf31b2 commit 3a3336c7e87b0046674a7fb4acf2a131c43f8128 @indexzero indexzero committed Apr 26, 2011
Showing with 22 additions and 3 deletions.
  1. +22 −3 lib/node-http-proxy.js
@@ -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
@@ -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`

0 comments on commit 3a3336c

Please sign in to comment.