mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
'end' event becomes 'close', added more try-catch handling
This commit is contained in:
parent
7249ef3ee7
commit
cd78af5fea
@ -315,22 +315,36 @@ HttpProxy.prototype = {
|
|||||||
sdata = sdata
|
sdata = sdata
|
||||||
.replace(remote_host, host)
|
.replace(remote_host, host)
|
||||||
.replace(remote_host, host);
|
.replace(remote_host, host);
|
||||||
|
try {
|
||||||
|
// Write printable
|
||||||
|
socket.write(sdata);
|
||||||
|
|
||||||
// Write printable
|
// Write non-printable
|
||||||
socket.write(sdata);
|
socket.write(data);
|
||||||
|
} catch (e) {
|
||||||
// Write non-printable
|
request.end();
|
||||||
socket.write(data);
|
socket.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Catch socket errors
|
||||||
|
socket.on('error', function() {
|
||||||
|
request.end();
|
||||||
|
});
|
||||||
|
|
||||||
// Remove data listener
|
// Remove data listener
|
||||||
request.socket.removeListener('data', t);
|
request.socket.removeListener('data', t);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Write upgrade-head
|
// Write upgrade-head
|
||||||
request.write(head);
|
try {
|
||||||
|
request.write(head);
|
||||||
|
} catch(e) {
|
||||||
|
request.end();
|
||||||
|
socket.end();
|
||||||
|
}
|
||||||
self.unwatch(socket);
|
self.unwatch(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
|
|
||||||
function onUpgrade(reverse_proxy) {
|
function onUpgrade(reverse_proxy) {
|
||||||
@ -340,14 +354,23 @@ HttpProxy.prototype = {
|
|||||||
reverse_proxy.on('data', listeners._r_data = function(data) {
|
reverse_proxy.on('data', listeners._r_data = function(data) {
|
||||||
// Pass data to client
|
// Pass data to client
|
||||||
if (socket.writable) {
|
if (socket.writable) {
|
||||||
socket.write(data);
|
try {
|
||||||
|
socket.write(data);
|
||||||
|
} catch (e) {
|
||||||
|
socket.end();
|
||||||
|
reverse_proxy.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('data', listeners._data = function(data){
|
socket.on('data', listeners._data = function(data){
|
||||||
// Pass data from client to server
|
// Pass data from client to server
|
||||||
// Socket thougth that it isn't writable
|
try {
|
||||||
reverse_proxy.write(data);
|
reverse_proxy.write(data);
|
||||||
|
} catch (e) {
|
||||||
|
reverse_proxy.end();
|
||||||
|
socket.end();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Detach event listeners from reverse_proxy
|
// Detach event listeners from reverse_proxy
|
||||||
@ -359,12 +382,12 @@ HttpProxy.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hook disconnections
|
// Hook disconnections
|
||||||
reverse_proxy.on('close', listeners._r_close = function() {
|
reverse_proxy.on('end', listeners._r_close = function() {
|
||||||
socket.end();
|
socket.end();
|
||||||
detach();
|
detach();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('close', listeners._close = function() {
|
socket.on('end', listeners._close = function() {
|
||||||
reverse_proxy.end();
|
reverse_proxy.end();
|
||||||
detach();
|
detach();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user