Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

savepoint, do not push

  • Loading branch information...
commit 0b106aebfcc5e10eaa823a1ab675e02dd8aac853 1 parent 28e851c
isaacs authored
Showing with 66 additions and 10 deletions.
  1. +45 −0 e.js
  2. +20 −10 lib/http.js
  3. +1 −0  lib/net.js
45 e.js
View
@@ -0,0 +1,45 @@
+var http = require('http');
+var net = require('net');
+
+var server = net.createServer(function(sock) {
+ sock.end(
+ 'HTTP/1.1 200 OK\r\n' +
+ 'Date: ' + new Date().toUTCString() + '\r\n' +
+ 'Content-Length: 1\r\n' + // wrong length
+ 'Content-Type: text/plain\r\n' +
+ '\r\n' +
+ '\r\n' +
+ 'This is too long.\r\n' +
+ '\r\n' +
+ '\r\n');
+ sock.destroySoon();
+ server.close();
+});
+
+server.listen(1337);
+
+var options = { host: 'localhost',
+ port: 1337,
+ path: '/',
+ method: 'HEAD' };
+
+var req = http.request(options, function (res) {
+ req.hadResponse = true;
+ res.hadResponse = true;
+ console.error('response:', res.statusCode, res.headers);
+
+ res.on('error', function(error) {
+ console.error('res error', error);
+ });
+
+ req.on('error', function(error) {
+ console.error('req error', error);
+ });
+
+ res.socket.on('error', function(error) {
+ console.error('socket error', error);
+ });
+});
+
+
+req.end();
30 lib/http.js
View
@@ -297,6 +297,7 @@ exports.IncomingMessage = IncomingMessage;
IncomingMessage.prototype.destroy = function(error) {
+ console.error('IncomingMessage.destroy', error);
this.socket.destroy(error);
};
@@ -454,6 +455,7 @@ exports.OutgoingMessage = OutgoingMessage;
OutgoingMessage.prototype.destroy = function(error) {
+ console.error('OutGoingMessage.destroy', error);
this.socket.destroy(error);
};
@@ -1309,6 +1311,8 @@ function socketCloseListener() {
}
function socketErrorListener(err) {
+ console.error('socket error listener', err)
+
var socket = this;
var parser = socket.parser;
var req = socket._httpMessage;
@@ -1353,9 +1357,10 @@ function socketOnData(d, start, end) {
var ret = parser.execute(d, start, end - start);
if (ret instanceof Error) {
- debug('parse error');
- freeParser(parser, req);
+ console.error('parse error', req && req.hadResponse);
+ console.error('socket.error =', socket.listeners('error').map(function (f) { return f.toString() }));
socket.destroy(ret);
+ freeParser(parser, req);
} else if (parser.incoming && parser.incoming.upgrade) {
// Upgrade or CONNECT
var bytesParsed = ret;
@@ -1375,6 +1380,7 @@ function socketOnData(d, start, end) {
// detach the socket
socket.emit('agentRemove');
+ console.error('detach socket');
socket.removeListener('close', socketCloseListener);
socket.removeListener('error', socketErrorListener);
@@ -1422,7 +1428,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
// to the content-length of the entity-body had the request
// been a GET.
var isHeadResponse = req.method == 'HEAD';
- debug('AGENT isHeadResponse ' + isHeadResponse);
+ console.error('AGENT isHeadResponse ' + isHeadResponse);
if (res.statusCode == 100) {
// restart the parser, as this is a continue message.
@@ -1440,6 +1446,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
+ console.error('emitting response');
req.emit('response', res);
req.res = res;
res.req = req;
@@ -1456,12 +1463,12 @@ function responseOnEnd() {
if (!req.shouldKeepAlive) {
if (socket.writable) {
- debug('AGENT socket.destroySoon()');
+ console.error('AGENT socket.destroySoon()');
socket.destroySoon();
}
assert(!socket.writable);
} else {
- debug('AGENT socket keep-alive');
+ console.error('AGENT socket keep-alive');
socket.removeListener('close', socketCloseListener);
socket.removeListener('error', socketErrorListener);
socket.emit('free');
@@ -1471,6 +1478,12 @@ function responseOnEnd() {
ClientRequest.prototype.onSocket = function(socket) {
var req = this;
+ console.error('add error listener');
+ socket.on('error', socketErrorListener);
+ socket.ondata = socketOnData;
+ socket.onend = socketOnEnd;
+ socket.on('close', socketCloseListener);
+
process.nextTick(function() {
var parser = parsers.alloc();
req.socket = socket;
@@ -1496,11 +1509,8 @@ ClientRequest.prototype.onSocket = function(socket) {
parser.maxHeaderPairs = 2000;
}
- socket.on('error', socketErrorListener);
- socket.ondata = socketOnData;
- socket.onend = socketOnEnd;
- socket.on('close', socketCloseListener);
parser.onIncoming = parserOnIncomingClient;
+
req.emit('socket', socket);
});
@@ -1672,7 +1682,7 @@ function connectionListener(socket) {
parser.maxHeaderPairs = 2000;
}
- socket.addListener('error', function(e) {
+ socket.on('error', function(e) {
self.emit('clientError', e);
});
1  lib/net.js
View
@@ -365,6 +365,7 @@ Socket.prototype._destroy = function(exception, cb) {
Socket.prototype.destroy = function(exception) {
+ console.error('Socket.destroy', exception);
this._destroy(exception);
};
Please sign in to comment.
Something went wrong with that request. Please try again.