http2: fix allowHttp1+Upgrade, broken by shouldUpgradeCallback · nodejs/node@c5d910a · GitHub
Skip to content

Commit c5d910a

Browse files
pimterrytargos
authored andcommitted
http2: fix allowHttp1+Upgrade, broken by shouldUpgradeCallback
This is required to use HTTP/1 websockets on an HTTP/2 server, which is fairly common as websockets over HTTP/2 is much less widely supported. This was broken by the recent shouldUpgradeCallback HTTP/1 addition, which wasn't correctly added to the corresponding allowHttp1 part of the HTTP/2 implementation. PR-URL: #59924 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 6e586a1 commit c5d910a

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

lib/internal/http2/core.js

Lines changed: 3 additions & 0 deletions

test/common/websocket-server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const crypto = require('crypto');
88
class WebSocketServer {
99
constructor({
1010
port = 0,
11+
server,
1112
}) {
1213
this.port = port;
13-
this.server = http.createServer();
14+
this.server = server || http.createServer();
1415
this.clients = new Set();
1516

1617
this.server.on('upgrade', this.handleUpgrade.bind(this));
@@ -44,6 +45,8 @@ class WebSocketServer {
4445
const opcode = buffer[0] & 0x0f;
4546

4647
if (opcode === 0x8) {
48+
// Send a minimal close frame in response:
49+
socket.write(Buffer.from([0x88, 0x00]));
4750
socket.end();
4851
this.clients.delete(socket);
4952
return;
Lines changed: 39 additions & 0 deletions

0 commit comments

Comments
 (0)