diff --git a/lib/http-proxy/passes/web-incoming.js b/lib/http-proxy/passes/web-incoming.js index 781b32692..8c4caabd4 100644 --- a/lib/http-proxy/passes/web-incoming.js +++ b/lib/http-proxy/passes/web-incoming.js @@ -170,21 +170,25 @@ module.exports = { proxyReq.on('response', function(proxyRes) { if(server) { server.emit('proxyRes', proxyRes, req, res); } - if(!res.headersSent && !options.selfHandleResponse) { - for(var i=0; i < web_o.length; i++) { - if(web_o[i](req, res, proxyRes, options)) { break; } + if (!(options.fallthrough === true && proxyRes.statusCode === 404)) { + if(!res.headersSent && !options.selfHandleResponse) { + for(var i=0; i < web_o.length; i++) { + if(web_o[i](req, res, proxyRes, options)) { break; } + } } - } - if (!res.finished) { - // Allow us to listen when the proxy has completed - proxyRes.on('end', function () { + if (!res.finished) { + // Allow us to listen when the proxy has completed + proxyRes.on('end', function () { + if (server) server.emit('end', req, res, proxyRes); + }); + // We pipe to the response unless its expected to be handled by the user + if (!options.selfHandleResponse) { + proxyRes.pipe(res); + } + } else { if (server) server.emit('end', req, res, proxyRes); - }); - // We pipe to the response unless its expected to be handled by the user - if (!options.selfHandleResponse) proxyRes.pipe(res); - } else { - if (server) server.emit('end', req, res, proxyRes); + } } }); }