Skip to content

Commit

Permalink
http: skip body and next message of CONNECT res
Browse files Browse the repository at this point in the history
When handling a response to `CONNECT` request - skip message body
and do not attempt to parse the next message. `CONNECT` requests are
used in similar sense to HTTP Upgrade.

Fix: #6198
PR-URL: #6279
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
indutny authored and Myles Borins committed Apr 20, 2016
1 parent 5305831 commit 16b23b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
// Responses to CONNECT request is handled as Upgrade.
if (req.method === 'CONNECT') {
res.upgrade = true;
return true; // skip body
return 2; // skip body, and the rest
}

// Responses to HEAD requests are crazy.
Expand Down
7 changes: 5 additions & 2 deletions lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,

parser.incoming.upgrade = upgrade;

var skipBody = false; // response to HEAD or CONNECT
var skipBody = 0; // response to HEAD or CONNECT

if (!upgrade) {
// For upgraded connections and CONNECT method request, we'll emit this
Expand All @@ -103,7 +103,10 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,
skipBody = parser.onIncoming(parser.incoming, shouldKeepAlive);
}

return skipBody;
if (typeof skipBody !== 'number')
return skipBody ? 1 : 0;
else
return skipBody;
}

// XXX This is a mess.
Expand Down
2 changes: 1 addition & 1 deletion src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Parser : public AsyncWrap {
return -1;
}

return head_response->IsTrue() ? 1 : 0;
return head_response->IntegerValue();
}


Expand Down

0 comments on commit 16b23b2

Please sign in to comment.