| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 77397c5 commit b0ebd23
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3136,9 +3136,13 @@ function initializeOptions(options) { | |||
| 3136 | 3136 | ||
| 3137 | 3137 | function initializeTLSOptions(options, servername) { | |
| 3138 | 3138 | options = initializeOptions(options); | |
| 3139 | - options.ALPNProtocols = ['h2']; | ||
| 3140 | - if (options.allowHTTP1 === true) | ||
| 3141 | - options.ALPNProtocols.push('http/1.1'); | ||
| 3139 | + | ||
| 3140 | + if (!options.ALPNCallback) { | ||
| 3141 | + options.ALPNProtocols = ['h2']; | ||
| 3142 | + if (options.allowHTTP1 === true) | ||
| 3143 | + options.ALPNProtocols.push('http/1.1'); | ||
| 3144 | + } | ||
| 3145 | + | ||
| 3142 | 3146 | if (servername !== undefined && !options.servername) | |
| 3143 | 3147 | options.servername = servername; | |
| 3144 | 3148 | return options; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,47 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const fixtures = require('../common/fixtures'); | ||
| 4 | + | ||
| 5 | + // This test verifies that http2 server support ALPNCallback option. | ||
| 6 | + | ||
| 7 | + if (!common.hasCrypto) common.skip('missing crypto'); | ||
| 8 | + | ||
| 9 | + const assert = require('assert'); | ||
| 10 | + const h2 = require('http2'); | ||
| 11 | + const tls = require('tls'); | ||
| 12 | + | ||
| 13 | + { | ||
| 14 | + // Server sets two incompatible ALPN options: | ||
| 15 | + assert.throws(() => h2.createSecureServer({ | ||
| 16 | + ALPNCallback: () => 'a', | ||
| 17 | + ALPNProtocols: ['b', 'c'] | ||
| 18 | + }), (error) => error.code === 'ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS'); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + { | ||
| 22 | + const server = h2.createSecureServer({ | ||
| 23 | + key: fixtures.readKey('rsa_private.pem'), | ||
| 24 | + cert: fixtures.readKey('rsa_cert.crt'), | ||
| 25 | + ALPNCallback: () => 'a', | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + server.on( | ||
| 29 | + 'secureConnection', | ||
| 30 | + common.mustCall((socket) => { | ||
| 31 | + assert.strictEqual(socket.alpnProtocol, 'a'); | ||
| 32 | + socket.end(); | ||
| 33 | + server.close(); | ||
| 34 | + }) | ||
| 35 | + ); | ||
| 36 | + | ||
| 37 | + server.listen(0, function() { | ||
| 38 | + const client = tls.connect({ | ||
| 39 | + port: server.address().port, | ||
| 40 | + rejectUnauthorized: false, | ||
| 41 | + ALPNProtocols: ['a'], | ||
| 42 | + }, common.mustCall(() => { | ||
| 43 | + assert.strictEqual(client.alpnProtocol, 'a'); | ||
| 44 | + client.end(); | ||
| 45 | + })); | ||
| 46 | + }); | ||
| 47 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments