From 3b86a7aae3fc366c5fa8645285a4368dbac7a0dc Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Sun, 6 Jan 2013 04:02:03 -0500 Subject: [PATCH] Add 'proxyResponse' event so observer can modify response headers or abort response. --- lib/node-http-proxy/http-proxy.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 2538a6e..8c0720b 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -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 Object.keys(response.headers).forEach(function (key) { res.setHeader(key, response.headers[key]);