GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: send error text in case of ALPN mismatch · nodejs/node@f137c18

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/http2
    • core.js
  • test/parallel
    • test-http2-https-fallback.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,8 +2489,17 @@ function connectionListener(socket) {
24892489
return httpConnectionListener.call(this, socket);
24902490
}
24912491
// Let event handler deal with the socket
2492-
if (!this.emit('unknownProtocol', socket))
2493-
socket.destroy();
2492+
debug(`Unknown protocol from ${socket.remoteAddress}:${socket.remotePort}`);
2493+
if (!this.emit('unknownProtocol', socket)) {
2494+
// We don't know what to do, so let's just tell the other side what's
2495+
// going on in a format that they *might* understand.
2496+
socket.end('HTTP/1.0 403 Forbidden\r\n' +
2497+
'Content-Type: text/plain\r\n\r\n' +
2498+
'Unknown ALPN Protocol, expected `h2` to be available.\n' +
2499+
'If this is a HTTP request: The server was not ' +
2500+
'configured with the `allowHTTP1` option or a ' +
2501+
'listener for the `unknownProtocol` event.\n');
2502+
}
24942503
return;
24952504
}
24962505

Collapse file

‎test/parallel/test-http2-https-fallback.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-https-fallback.js
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const fixtures = require('../common/fixtures');
66
if (!common.hasCrypto)
77
common.skip('missing crypto');
88

9-
const { strictEqual } = require('assert');
9+
const { strictEqual, ok } = require('assert');
1010
const { createSecureContext } = require('tls');
1111
const { createSecureServer, connect } = require('http2');
1212
const { get } = require('https');
@@ -131,10 +131,17 @@ function onSession(session) {
131131

132132
// HTTP/1.1 client
133133
get(Object.assign(parse(origin), clientOptions), common.mustNotCall())
134-
.on('error', common.mustCall(cleanup));
134+
.on('error', common.mustCall(cleanup))
135+
.end();
135136

136137
// Incompatible ALPN TLS client
138+
let text = '';
137139
tls(Object.assign({ port, ALPNProtocols: ['fake'] }, clientOptions))
138-
.on('error', common.mustCall(cleanup));
140+
.setEncoding('utf8')
141+
.on('data', (chunk) => text += chunk)
142+
.on('end', common.mustCall(() => {
143+
ok(/Unknown ALPN Protocol, expected `h2` to be available/.test(text));
144+
cleanup();
145+
}));
139146
}));
140147
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.