From 8b48a9fdab01624f7249c53f25919b1295eefb10 Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Wed, 9 Apr 2014 13:38:13 -0400 Subject: [PATCH] [api] emit a start an an end event --- lib/http-proxy/passes/web-incoming.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/http-proxy/passes/web-incoming.js b/lib/http-proxy/passes/web-incoming.js index 1840d61..29ae306 100644 --- a/lib/http-proxy/passes/web-incoming.js +++ b/lib/http-proxy/passes/web-incoming.js @@ -90,6 +90,13 @@ web_o = Object.keys(web_o).map(function(pass) { */ function stream(req, res, options, _, server, clb) { + + // + // And we begin! + // + if (!clb) { + server.emit('start', req, res, options.target) + } if(options.forward) { // If forward enable, so just pipe the request var forwardReq = (options.forward.protocol === 'https:' ? https : http).request( @@ -122,6 +129,15 @@ web_o = Object.keys(web_o).map(function(pass) { if(web_o[i](req, res, proxyRes)) { break; } } + // + // Allow us to listen when the proxy has completed + // + proxyRes.on('end', function () { + if (!clb) { + server.emit('end', req, res, proxyRes); + } + }) + proxyRes.pipe(res); });