summaryrefslogtreecommitdiff
path: root/lib/_http_client.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-04-12 19:57:19 +0200
committerMatteo Collina <hello@matteocollina.com>2018-04-16 11:02:23 +0200
commitf7fbbeedc609f56c898230971b44d3dde0934dc9 (patch)
tree3b6a5badaa17cd1fe8ba86d6ccfc0992ea1307cd /lib/_http_client.js
parentcf48d1db660888cd3bfd14953a27527d56e90e6a (diff)
downloadandroid-node-v8-f7fbbeedc609f56c898230971b44d3dde0934dc9.tar.gz
android-node-v8-f7fbbeedc609f56c898230971b44d3dde0934dc9.tar.bz2
android-node-v8-f7fbbeedc609f56c898230971b44d3dde0934dc9.zip
http: relax requirements on upgrade listener
The http spec does not say anything about Upgrade headers making protocol switch mandatory but Node.js implements them as if they are. Relax the requirements to only destroy the socket if no upgrade listener exists on the client when status code is 101. PR-URL: https://github.com/nodejs/node/pull/19981 Fixes: https://github.com/nodejs/node/issues/11552 Refs: https://tools.ietf.org/html/rfc7230#section-6.7 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/_http_client.js')
-rw-r--r--lib/_http_client.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js
index 5be1632fe5..c3ef9de204 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -426,7 +426,7 @@ function socketOnData(d) {
req.socket._hadError = true;
req.emit('error', ret);
} else if (parser.incoming && parser.incoming.upgrade) {
- // Upgrade or CONNECT
+ // Upgrade (if status code 101) or CONNECT
var bytesParsed = ret;
var res = parser.incoming;
req.res = res;
@@ -453,7 +453,7 @@ function socketOnData(d) {
req.emit(eventName, res, socket, bodyHead);
req.emit('close');
} else {
- // Got Upgrade header or CONNECT method, but have no handler.
+ // Requested Upgrade or used CONNECT method, but have no handler.
socket.destroy();
}
} else if (parser.incoming && parser.incoming.complete &&
@@ -492,6 +492,10 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
}
req.res = res;
+ // Skip body and treat as Upgrade.
+ if (res.upgrade)
+ return 2;
+
// Responses to CONNECT request is handled as Upgrade.
const method = req.method;
if (method === 'CONNECT') {