Skip to content

Commit

Permalink
Add a test for the proxyRes event
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-one committed May 11, 2014
1 parent 1213e46 commit 1385635
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/lib-http-proxy-passes-web-incoming-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 1385635

Please sign in to comment.