Skip to content

Commit

Permalink
Fix test-http-upgrade-server and test-http-parser
Browse files Browse the repository at this point in the history
Problem was introduced in last http-parser upgrade which fixed a long
standing bug with the upgrade event and removed several callbacks.
  • Loading branch information
ry committed Aug 9, 2011
1 parent 0df08c6 commit 2126989
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
10 changes: 4 additions & 6 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions lib/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 1 addition & 9 deletions test/simple/test-http-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2126989

Please sign in to comment.