我试图为http3设置一个测试环境,以便学习。
我到目前为止所做的:
我创建了一个包含示例内容的脚本
'use strict';
const key = getTLSKeySomehow();
const cert = getTLSCertSomehow();
const { createQuicSocket } = require('net');
// Create the QUIC UDP IPv4 socket bound to local IP port 1234
const socket = createQuicSocket({ endpoint: { port: 1234 } });
socket.on('session', async (session) => {
// A new server side session has been created!
// The peer opened a new stream!
session.on('stream', (stream) => {
// Let's say hello
stream.end('Hello World');
// Let's see what the peer has to say...
stream.setEncoding('utf8');
stream.on('data', console.log);
stream.on('end', () => console.log('stream ended'));
});
const uni = await session.openStream({ halfOpen: true });
uni.write('hi ');
uni.end('from the server!');
});
// Tell the socket to operate as a server using the given
// key and certificate to secure new connections, using
// the fictional 'hello' application protocol.
(async function() {
await socket.listen({ key, cert, alpn: 'h3-25' });
console.log('The socket is listening for sessions!');
})();对于将来的读者来说,getTLSKeySomehow()和getTLSCertSomehow()函数可以被以下内容所取代:
const fs = require("fs")
const key = fs.readFileSync('privkey.pem')
const cert = fs.readFileSync('cert.pem')然后,我试图打开网页,在火狐中启用http3,并在about:config中启用功能标志network.http.http3.enabled。使用地址https://my.dev.domain.name:1234/,但这不起作用。
使用curl不起作用,值得注意的是,我在Windows 10上使用了WSL,每次访问相同的curl超时url。只是为了检查我的设置是否正常:我可以验证Firefox可以通过www.google.com访问完美的http3。
当我用相同的键实现第二个http2端点时,没有任何证书警告,这很好。
我如何调试我做错了什么?
发布于 2021-01-07 06:53:45
您的代码示例只是实现QUIC --它是HTTP/3下的传输协议(类似于TCP + TLS是HTTP/1.1下的传输协议)。
这意味着您需要在Quic之上实现HTTP/3的附加代码。理想情况下,您需要一个库,因为它相当复杂。以下是需要执行的最新规范草案的链接:
我认为node.js最终也会添加对这些功能的支持,从而使这项任务变得更容易。
没有HTTP/3支持,您可以在测试服务器上测试纯QUIC流(没有HTTP语义)。您可以使用任何不同的QUIC库来完成这个任务,但是可能没有像curl这样的开箱即用的CLI工具。
https://stackoverflow.com/questions/65531418
复制相似问题