Fix test-http-upgrade-server and test-http-parser
authorRyan Dahl <ry@tinyclouds.org>
Tue, 9 Aug 2011 00:08:38 +0000 (17:08 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Tue, 9 Aug 2011 00:12:26 +0000 (17:12 -0700)
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
lib/http2.js
test/simple/test-http-parser.js

index 794af64..8cebfcf 100644 (file)
@@ -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);
index 7947485..be2c959 100644 (file)
@@ -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);
index ccfd676..c85be88 100644 (file)
@@ -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