| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cd914ca commit f137c18
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2489,8 +2489,17 @@ function connectionListener(socket) { | |||
| 2489 | 2489 | return httpConnectionListener.call(this, socket); | |
| 2490 | 2490 | } | |
| 2491 | 2491 | // 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 | + } | ||
| 2494 | 2503 | return; | |
| 2495 | 2504 | } | |
| 2496 | 2505 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ const fixtures = require('../common/fixtures'); | |||
| 6 | 6 | if (!common.hasCrypto) | |
| 7 | 7 | common.skip('missing crypto'); | |
| 8 | 8 | ||
| 9 | - const { strictEqual } = require('assert'); | ||
| 9 | + const { strictEqual, ok } = require('assert'); | ||
| 10 | 10 | const { createSecureContext } = require('tls'); | |
| 11 | 11 | const { createSecureServer, connect } = require('http2'); | |
| 12 | 12 | const { get } = require('https'); | |
@@ -131,10 +131,17 @@ function onSession(session) { | |||
| 131 | 131 | ||
| 132 | 132 | // HTTP/1.1 client | |
| 133 | 133 | get(Object.assign(parse(origin), clientOptions), common.mustNotCall()) | |
| 134 | - .on('error', common.mustCall(cleanup)); | ||
| 134 | + .on('error', common.mustCall(cleanup)) | ||
| 135 | + .end(); | ||
| 135 | 136 | ||
| 136 | 137 | // Incompatible ALPN TLS client | |
| 138 | + let text = ''; | ||
| 137 | 139 | 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 | + })); | ||
| 139 | 146 | })); | |
| 140 | 147 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments