Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

http: Emit all socket errors on the request object

This fixes #3945
  • Loading branch information...
commit e6ced9984f445f9d6242d2f6a938148bcf69feb3 1 parent 4488a69
isaacs authored
Showing with 20 additions and 11 deletions.
  1. +9 −1 lib/http.js
  2. +11 −10 test/simple/test-http-blank-header.js
10 lib/http.js
View
@@ -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) {
21 test/simple/test-http-blank-header.js
View
@@ -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);
});
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.