mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Fixed issue where error callback would not invoke, including new test cases. Added req/res values to error events.
Conflicts: lib/http-proxy/passes/web-incoming.js
This commit is contained in:
parent
5d66ce11bb
commit
0bfb9be418
@ -106,11 +106,10 @@ web_o = Object.keys(web_o).map(function(pass) {
|
||||
|
||||
// Error Handler
|
||||
proxyReq.on('error', function(err){
|
||||
if(server) {
|
||||
server.emit('error', err);
|
||||
}
|
||||
else {
|
||||
clb(err);
|
||||
if (clb) {
|
||||
clb(err);
|
||||
} else {
|
||||
server.emit('error', err, req, res);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
92
test/lib-http-proxy-integration-test.js
Normal file
92
test/lib-http-proxy-integration-test.js
Normal file
@ -0,0 +1,92 @@
|
||||
var httpProxy = require('../lib/http-proxy'),
|
||||
expect = require('expect.js'),
|
||||
http = require('http');
|
||||
|
||||
|
||||
describe('lib/http-proxy.js', function() {
|
||||
|
||||
describe('#createProxyServer with target options for integration into existing server', function () {
|
||||
it('should proxy the request using the web proxy handler', function (done) {
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
target: 'http://127.0.0.1:8080'
|
||||
});
|
||||
|
||||
function requestHandler(req, res) {
|
||||
proxy.web(req, res);
|
||||
}
|
||||
|
||||
var proxyServer = http.createServer(requestHandler);
|
||||
|
||||
var source = http.createServer(function(req, res) {
|
||||
source.close();
|
||||
proxyServer.close();
|
||||
expect(req.method).to.eql('GET');
|
||||
expect(req.headers.host.split(':')[1]).to.eql('8082');
|
||||
done();
|
||||
});
|
||||
|
||||
proxyServer.listen('8082');
|
||||
source.listen('8080');
|
||||
|
||||
http.request('http://127.0.0.1:8082', function() {}).end();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createProxyServer() for integration into existing server with error response', function () {
|
||||
it('should proxy the request and handle error via callback', function(done) {
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
target: 'http://127.0.0.1:8080'
|
||||
});
|
||||
|
||||
var proxyServer = http.createServer(requestHandler);
|
||||
|
||||
function requestHandler(req, res) {
|
||||
proxy.web(req, res, function (err) {
|
||||
proxyServer.close();
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.be('ECONNREFUSED');
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
proxyServer.listen('8082');
|
||||
|
||||
http.request({
|
||||
hostname: '127.0.0.1',
|
||||
port: '8082',
|
||||
method: 'GET',
|
||||
}, function() {}).end();
|
||||
});
|
||||
|
||||
it('should proxy the request and handle error event listener', function(done) {
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
target: 'http://127.0.0.1:8080'
|
||||
});
|
||||
|
||||
var proxyServer = http.createServer(requestHandler);
|
||||
|
||||
function requestHandler(req, res) {
|
||||
proxy.once('error', function (err, errReq, errRes) {
|
||||
proxyServer.close();
|
||||
expect(err).to.be.an(Error);
|
||||
expect(errReq).to.be.equal(req);
|
||||
expect(errRes).to.be.equal(res);
|
||||
expect(err.code).to.be('ECONNREFUSED');
|
||||
done();
|
||||
});
|
||||
|
||||
proxy.web(req, res);
|
||||
}
|
||||
|
||||
proxyServer.listen('8082');
|
||||
|
||||
http.request({
|
||||
hostname: '127.0.0.1',
|
||||
port: '8082',
|
||||
method: 'GET',
|
||||
}, function() {}).end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user