Skip to content

Commit 7e61f0c

Browse files
committed
Moved error handling to response.on('end'), fixed error handling in websocket's part
1 parent 56003b5 commit 7e61f0c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/node-http-proxy.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ HttpProxy.prototype = {
159159
if(req.method !== 'HEAD') {
160160
res.write('An error has occurred: ' + sys.puts(JSON.stringify(err)));
161161
}
162-
162+
163+
// Response end may never come so removeListener here
164+
reverse_proxy.removeListener('error', error);
163165
res.end();
164166
};
165167

@@ -195,6 +197,7 @@ HttpProxy.prototype = {
195197
response.addListener('end', function () {
196198
// Remark: Emit the end event for testability
197199
self.emitter.emit('proxy', null, self.body);
200+
reverse_proxy.removeListener('error', error);
198201
res.end();
199202
});
200203
});
@@ -207,7 +210,6 @@ HttpProxy.prototype = {
207210
// At the end of the client request, we are going to stop the proxied request
208211
req.addListener('end', function () {
209212
reverse_proxy.end();
210-
reverse_proxy.removeListener('error', error);
211213
});
212214

213215
self.unwatch(req);
@@ -276,8 +278,6 @@ HttpProxy.prototype = {
276278
var request = client.request('GET', req.url, headers);
277279

278280
var errorListener = function (error) {
279-
p.emit('error', error);
280-
request.emit('error', error);
281281
socket.end();
282282
}
283283

0 commit comments

Comments
 (0)