Skip to content

Commit

Permalink
[api] emit a start an an end event
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrugzz committed Apr 9, 2014
1 parent c6b7a79 commit 8b48a9f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/http-proxy/passes/web-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit 8b48a9f

Please sign in to comment.