Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

savepoint, do not push

  • Loading branch information...
commit 0b106aebfcc5e10eaa823a1ab675e02dd8aac853 1 parent 28e851c
Isaac Z. Schlueter authored

Showing 3 changed files with 66 additions and 10 deletions. Show diff stats Hide diff stats

  1. +45 0 e.js
  2. +20 10 lib/http.js
  3. +1 0  lib/net.js
45 e.js
... ... @@ -0,0 +1,45 @@
  1 +var http = require('http');
  2 +var net = require('net');
  3 +
  4 +var server = net.createServer(function(sock) {
  5 + sock.end(
  6 + 'HTTP/1.1 200 OK\r\n' +
  7 + 'Date: ' + new Date().toUTCString() + '\r\n' +
  8 + 'Content-Length: 1\r\n' + // wrong length
  9 + 'Content-Type: text/plain\r\n' +
  10 + '\r\n' +
  11 + '\r\n' +
  12 + 'This is too long.\r\n' +
  13 + '\r\n' +
  14 + '\r\n');
  15 + sock.destroySoon();
  16 + server.close();
  17 +});
  18 +
  19 +server.listen(1337);
  20 +
  21 +var options = { host: 'localhost',
  22 + port: 1337,
  23 + path: '/',
  24 + method: 'HEAD' };
  25 +
  26 +var req = http.request(options, function (res) {
  27 + req.hadResponse = true;
  28 + res.hadResponse = true;
  29 + console.error('response:', res.statusCode, res.headers);
  30 +
  31 + res.on('error', function(error) {
  32 + console.error('res error', error);
  33 + });
  34 +
  35 + req.on('error', function(error) {
  36 + console.error('req error', error);
  37 + });
  38 +
  39 + res.socket.on('error', function(error) {
  40 + console.error('socket error', error);
  41 + });
  42 +});
  43 +
  44 +
  45 +req.end();
30 lib/http.js
@@ -297,6 +297,7 @@ exports.IncomingMessage = IncomingMessage;
297 297
298 298
299 299 IncomingMessage.prototype.destroy = function(error) {
  300 + console.error('IncomingMessage.destroy', error);
300 301 this.socket.destroy(error);
301 302 };
302 303
@@ -454,6 +455,7 @@ exports.OutgoingMessage = OutgoingMessage;
454 455
455 456
456 457 OutgoingMessage.prototype.destroy = function(error) {
  458 + console.error('OutGoingMessage.destroy', error);
457 459 this.socket.destroy(error);
458 460 };
459 461
@@ -1309,6 +1311,8 @@ function socketCloseListener() {
1309 1311 }
1310 1312
1311 1313 function socketErrorListener(err) {
  1314 + console.error('socket error listener', err)
  1315 +
1312 1316 var socket = this;
1313 1317 var parser = socket.parser;
1314 1318 var req = socket._httpMessage;
@@ -1353,9 +1357,10 @@ function socketOnData(d, start, end) {
1353 1357
1354 1358 var ret = parser.execute(d, start, end - start);
1355 1359 if (ret instanceof Error) {
1356   - debug('parse error');
1357   - freeParser(parser, req);
  1360 + console.error('parse error', req && req.hadResponse);
  1361 + console.error('socket.error =', socket.listeners('error').map(function (f) { return f.toString() }));
1358 1362 socket.destroy(ret);
  1363 + freeParser(parser, req);
1359 1364 } else if (parser.incoming && parser.incoming.upgrade) {
1360 1365 // Upgrade or CONNECT
1361 1366 var bytesParsed = ret;
@@ -1375,6 +1380,7 @@ function socketOnData(d, start, end) {
1375 1380
1376 1381 // detach the socket
1377 1382 socket.emit('agentRemove');
  1383 + console.error('detach socket');
1378 1384 socket.removeListener('close', socketCloseListener);
1379 1385 socket.removeListener('error', socketErrorListener);
1380 1386
@@ -1422,7 +1428,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
1422 1428 // to the content-length of the entity-body had the request
1423 1429 // been a GET.
1424 1430 var isHeadResponse = req.method == 'HEAD';
1425   - debug('AGENT isHeadResponse ' + isHeadResponse);
  1431 + console.error('AGENT isHeadResponse ' + isHeadResponse);
1426 1432
1427 1433 if (res.statusCode == 100) {
1428 1434 // restart the parser, as this is a continue message.
@@ -1440,6 +1446,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
1440 1446
1441 1447
1442 1448 DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
  1449 + console.error('emitting response');
1443 1450 req.emit('response', res);
1444 1451 req.res = res;
1445 1452 res.req = req;
@@ -1456,12 +1463,12 @@ function responseOnEnd() {
1456 1463
1457 1464 if (!req.shouldKeepAlive) {
1458 1465 if (socket.writable) {
1459   - debug('AGENT socket.destroySoon()');
  1466 + console.error('AGENT socket.destroySoon()');
1460 1467 socket.destroySoon();
1461 1468 }
1462 1469 assert(!socket.writable);
1463 1470 } else {
1464   - debug('AGENT socket keep-alive');
  1471 + console.error('AGENT socket keep-alive');
1465 1472 socket.removeListener('close', socketCloseListener);
1466 1473 socket.removeListener('error', socketErrorListener);
1467 1474 socket.emit('free');
@@ -1471,6 +1478,12 @@ function responseOnEnd() {
1471 1478 ClientRequest.prototype.onSocket = function(socket) {
1472 1479 var req = this;
1473 1480
  1481 + console.error('add error listener');
  1482 + socket.on('error', socketErrorListener);
  1483 + socket.ondata = socketOnData;
  1484 + socket.onend = socketOnEnd;
  1485 + socket.on('close', socketCloseListener);
  1486 +
1474 1487 process.nextTick(function() {
1475 1488 var parser = parsers.alloc();
1476 1489 req.socket = socket;
@@ -1496,11 +1509,8 @@ ClientRequest.prototype.onSocket = function(socket) {
1496 1509 parser.maxHeaderPairs = 2000;
1497 1510 }
1498 1511
1499   - socket.on('error', socketErrorListener);
1500   - socket.ondata = socketOnData;
1501   - socket.onend = socketOnEnd;
1502   - socket.on('close', socketCloseListener);
1503 1512 parser.onIncoming = parserOnIncomingClient;
  1513 +
1504 1514 req.emit('socket', socket);
1505 1515 });
1506 1516
@@ -1672,7 +1682,7 @@ function connectionListener(socket) {
1672 1682 parser.maxHeaderPairs = 2000;
1673 1683 }
1674 1684
1675   - socket.addListener('error', function(e) {
  1685 + socket.on('error', function(e) {
1676 1686 self.emit('clientError', e);
1677 1687 });
1678 1688
1  lib/net.js
@@ -365,6 +365,7 @@ Socket.prototype._destroy = function(exception, cb) {
365 365
366 366
367 367 Socket.prototype.destroy = function(exception) {
  368 + console.error('Socket.destroy', exception);
368 369 this._destroy(exception);
369 370 };
370 371

0 comments on commit 0b106ae

Please sign in to comment.
Something went wrong with that request. Please try again.