From 1385635e18f081af759c8e088f2f6b0219df83db Mon Sep 17 00:00:00 2001 From: Bryce Gibson Date: Mon, 12 May 2014 08:44:02 +1000 Subject: [PATCH] Add a test for the proxyRes event --- ...lib-http-proxy-passes-web-incoming-test.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/lib-http-proxy-passes-web-incoming-test.js b/test/lib-http-proxy-passes-web-incoming-test.js index b25ad6e12..49ffa9ef4 100644 --- a/test/lib-http-proxy-passes-web-incoming-test.js +++ b/test/lib-http-proxy-passes-web-incoming-test.js @@ -127,4 +127,32 @@ describe('#createProxyServer.web() using own http server', function () { method: 'GET', }, function() {}).end(); }); + + it('should proxy the request and provide a proxyRes event with the request and response parameters', function(done) { + var proxy = httpProxy.createProxyServer({ + target: 'http://127.0.0.1:8080' + }); + + function requestHandler(req, res) { + proxy.once('proxyRes', function (proxyRes, pReq, pRes) { + source.close(); + proxyServer.close(); + expect(pReq).to.be.equal(req); + expect(pRes).to.be.equal(res); + done(); + }); + + proxy.web(req, res); + } + + var proxyServer = http.createServer(requestHandler); + + var source = http.createServer(function(req, res) { + res.end('Response'); + }); + + proxyServer.listen('8084'); + source.listen('8080'); + http.request('http://127.0.0.1:8084', function() {}).end(); + }); }); \ No newline at end of file