From 2126989a32f74dea0476c770f5dda826f12bc457 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 8 Aug 2011 17:08:38 -0700 Subject: [PATCH] Fix test-http-upgrade-server and test-http-parser Problem was introduced in last http-parser upgrade which fixed a long standing bug with the upgrade event and removed several callbacks. --- lib/http.js | 10 ++++------ lib/http2.js | 10 ++++------ test/simple/test-http-parser.js | 10 +--------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/lib/http.js b/lib/http.js index 794af64e87..8cebfcf5ac 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1028,9 +1028,8 @@ function connectionListener(socket) { var req = parser.incoming; - // This is start + byteParsed + 1 due to the error of getting \n - // in the upgradeHead from the closing lines of the headers - var upgradeHead = d.slice(start + bytesParsed + 1, end); + // This is start + byteParsed + var upgradeHead = d.slice(start + bytesParsed, end); if (self.listeners('upgrade').length) { self.emit('upgrade', req, req.socket, upgradeHead); @@ -1234,9 +1233,8 @@ Agent.prototype._establishNewConnection = function() { assert(socket._httpMessage); socket._httpMessage.res = res; - // This is start + byteParsed + 1 due to the error of getting \n - // in the upgradeHead from the closing lines of the headers - var upgradeHead = d.slice(start + bytesParsed + 1, end); + // This is start + byteParsed + var upgradeHead = d.slice(start + bytesParsed, end); // Make sure we don't try to send HTTP requests to it. self._removeSocket(socket); diff --git a/lib/http2.js b/lib/http2.js index 7947485e05..be2c9596eb 100644 --- a/lib/http2.js +++ b/lib/http2.js @@ -1104,9 +1104,8 @@ ClientRequest.prototype.onSocket = function(socket) { var res = parser.incoming; req.res = res; - // This is start + byteParsed + 1 due to the error of getting \n - // in the upgradeHead from the closing lines of the headers - var upgradeHead = d.slice(start + bytesParsed + 1, end); + // This is start + byteParsed + var upgradeHead = d.slice(start + bytesParsed, end); if (req.listeners('upgrade').length) { // Emit 'upgrade' on the Agent. req.upgraded = true; @@ -1350,9 +1349,8 @@ function connectionListener(socket) { var req = parser.incoming; - // This is start + byteParsed + 1 due to the error of getting \n - // in the upgradeHead from the closing lines of the headers - var upgradeHead = d.slice(start + bytesParsed + 1, end); + // This is start + byteParsed + var upgradeHead = d.slice(start + bytesParsed, end); if (self.listeners('upgrade').length) { self.emit('upgrade', req, req.socket, upgradeHead); diff --git a/test/simple/test-http-parser.js b/test/simple/test-http-parser.js index ccfd676a33..c85be88a74 100644 --- a/test/simple/test-http-parser.js +++ b/test/simple/test-http-parser.js @@ -58,16 +58,8 @@ parser.onURL = function(b, off, len) { callbacks++; }; -parser.onPath = function(b, off, length) { - console.log('path [' + off + ', ' + length + ']'); - var path = b.toString('ascii', off, off + length); - console.log('path = "' + path + '"'); - assert.equal('/hello', path); - callbacks++; -}; - parser.execute(buffer, 0, request.length); -assert.equal(4, callbacks); +assert.equal(3, callbacks); // // Check that if we throw an error in the callbacks that error will be