Add 'proxyResponse' event so observer can modify response headers or abort response.

This commit is contained in:
Colin Mollenhour 2013-01-06 04:02:03 -05:00 committed by indexzero
parent 4c130f5dac
commit 3b86a7aae3

View File

@ -301,6 +301,13 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
} }
}); });
// Allow observer to modify headers or abort response
try { req.emit('proxyResponse', req, res, response) }
catch (ex) {
errState = true;
return;
}
// Set the headers of the client response // Set the headers of the client response
Object.keys(response.headers).forEach(function (key) { Object.keys(response.headers).forEach(function (key) {
res.setHeader(key, response.headers[key]); res.setHeader(key, response.headers[key]);