[api] emit a start an an end event

This commit is contained in:
Jarrett Cruger 2014-04-09 13:38:13 -04:00
parent c6b7a7919f
commit 8b48a9fdab

View File

@ -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);
});