Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

http: Emit all socket errors on the request object #4620

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/http.js
Expand Up @@ -1777,7 +1777,15 @@ function connectionListener(socket) {
}

socket.addListener('error', function(e) {
self.emit('clientError', e, this);
// if we have a request, then emit the error there
// otherwise just emit a clientError on the server
// destroy the socket either way, though
if (parser.incoming)
parser.incoming.emit('error', e);
else
self.emit('clientError', e, this);

socket.destroy();
});

socket.ondata = function(d, start, end) {
Expand Down
21 changes: 11 additions & 10 deletions test/simple/test-http-blank-header.js
Expand Up @@ -34,8 +34,12 @@ var server = http.createServer(function(req, res) {
assert.deepEqual({
host: 'mapdevel.trolologames.ru:443',
origin: 'http://mapdevel.trolologames.ru',
cookie: ''
cookie: '',
'content-length': '12'
}, req.headers);

req.setEncoding('utf8');
req.on('data', console.error);
});


Expand All @@ -44,18 +48,15 @@ server.listen(common.PORT, function() {

c.on('connect', function() {
common.error('client wrote message');
c.write('GET /blah HTTP/1.1\r\n' +
'Host: mapdevel.trolologames.ru:443\r\n' +
'Cookie:\r\n' +
'Origin: http://mapdevel.trolologames.ru\r\n' +
'\r\n\r\nhello world'
c.end('GET /blah HTTP/1.1\r\n' +
'Host: mapdevel.trolologames.ru:443\r\n' +
'Cookie:\r\n' +
'Origin: http://mapdevel.trolologames.ru\r\n' +
'Content-Length: 12\r\n' +
'\r\nhello, world'
);
});

c.on('end', function() {
c.end();
});

c.on('close', function() {
common.error('client close');
server.close();
Expand Down