Skip to content

Commit 1385635

Browse files
committed
Add a test for the proxyRes event
1 parent 1213e46 commit 1385635

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: test/lib-http-proxy-passes-web-incoming-test.js

+28
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,32 @@ describe('#createProxyServer.web() using own http server', function () {
127127
method: 'GET',
128128
}, function() {}).end();
129129
});
130+
131+
it('should proxy the request and provide a proxyRes event with the request and response parameters', function(done) {
132+
var proxy = httpProxy.createProxyServer({
133+
target: 'http://127.0.0.1:8080'
134+
});
135+
136+
function requestHandler(req, res) {
137+
proxy.once('proxyRes', function (proxyRes, pReq, pRes) {
138+
source.close();
139+
proxyServer.close();
140+
expect(pReq).to.be.equal(req);
141+
expect(pRes).to.be.equal(res);
142+
done();
143+
});
144+
145+
proxy.web(req, res);
146+
}
147+
148+
var proxyServer = http.createServer(requestHandler);
149+
150+
var source = http.createServer(function(req, res) {
151+
res.end('Response');
152+
});
153+
154+
proxyServer.listen('8084');
155+
source.listen('8080');
156+
http.request('http://127.0.0.1:8084', function() {}).end();
157+
});
130158
});

0 commit comments

Comments
 (0)