mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
test closing upstream socket prior to upgrade
should close the client socket with ECONNRESET, but currently is left hanging.
This commit is contained in:
parent
f0bf741815
commit
77305489d9
@ -281,6 +281,11 @@ describe('lib/http-proxy.js', function() {
|
||||
client.send('hello there');
|
||||
});
|
||||
|
||||
client.on('error', function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.be('ECONNRESET');
|
||||
});
|
||||
|
||||
proxy.on('error', function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.be('ECONNREFUSED');
|
||||
@ -289,6 +294,41 @@ describe('lib/http-proxy.js', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should close client socket if upstream is closed before upgrade', function (done) {
|
||||
var ports = { source: gen.port, proxy: gen.port };
|
||||
var server = http.createServer();
|
||||
server.on('upgrade', function (req, socket, head) {
|
||||
var response = [
|
||||
'HTTP/1.1 404 Not Found',
|
||||
'Content-type: text/html',
|
||||
'',
|
||||
''
|
||||
];
|
||||
socket.write(response.join('\r\n'));
|
||||
socket.end();
|
||||
});
|
||||
server.listen(ports.source);
|
||||
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
// note: we don't ever listen on this port
|
||||
target: 'ws://127.0.0.1:' + ports.source,
|
||||
ws: true
|
||||
}),
|
||||
proxyServer = proxy.listen(ports.proxy),
|
||||
client = new ws('ws://127.0.0.1:' + ports.proxy);
|
||||
|
||||
client.on('open', function () {
|
||||
client.send('hello there');
|
||||
});
|
||||
|
||||
client.on('error', function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.code).to.be('ECONNRESET');
|
||||
proxyServer.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should proxy a socket.io stream', function (done) {
|
||||
var ports = { source: gen.port, proxy: gen.port };
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user