Skip to content

Commit 8b48a9f

Browse files
committed
[api] emit a start an an end event
1 parent c6b7a79 commit 8b48a9f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/http-proxy/passes/web-incoming.js

+16
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ web_o = Object.keys(web_o).map(function(pass) {
9090
*/
9191

9292
function stream(req, res, options, _, server, clb) {
93+
94+
//
95+
// And we begin!
96+
//
97+
if (!clb) {
98+
server.emit('start', req, res, options.target)
99+
}
93100
if(options.forward) {
94101
// If forward enable, so just pipe the request
95102
var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
@@ -122,6 +129,15 @@ web_o = Object.keys(web_o).map(function(pass) {
122129
if(web_o[i](req, res, proxyRes)) { break; }
123130
}
124131

132+
//
133+
// Allow us to listen when the proxy has completed
134+
//
135+
proxyRes.on('end', function () {
136+
if (!clb) {
137+
server.emit('end', req, res, proxyRes);
138+
}
139+
})
140+
125141
proxyRes.pipe(res);
126142
});
127143

0 commit comments

Comments
 (0)