mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Add a test for the proxyRes event
This commit is contained in:
parent
1213e46b1b
commit
1385635e18
@ -127,4 +127,32 @@ describe('#createProxyServer.web() using own http server', function () {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
}, function() {}).end();
|
}, 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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user