From 07fd52e5aafccd3417ce978cc86b3a457cdb5bab Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 19 Apr 2016 10:51:05 -0400 Subject: [PATCH] http: skip body and next message of CONNECT res 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: https://github.com/nodejs/node/pull/6198 PR-URL: https://github.com/nodejs/node/pull/6279 Reviewed-By: Brian White Reviewed-By: James M Snell --- lib/_http_client.js | 2 +- lib/_http_common.js | 7 +++++-- src/node_http_parser.cc | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 371da638f9b98a..3e3b9966c275bf 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -393,7 +393,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. diff --git a/lib/_http_common.js b/lib/_http_common.js index 08f93d8c4d04a2..1e6490eaffb6ce 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -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 @@ -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. diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 6b15aa8c72d531..c062feea535604 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -301,7 +301,7 @@ class Parser : public AsyncWrap { return -1; } - return head_response->IsTrue() ? 1 : 0; + return head_response->IntegerValue(); }