gpt4 book ai didi

javascript - 调试 http3 设置

转载 作者:行者123 更新时间:2023-12-03 12:18:18 25 4
gpt4 key购买 nike

我正在尝试为 http3 设置一个测试环境,只是为了学习。

到目前为止我做了什么:

  • 使用 dns-01 创建了一个真正的 let's encrypt 证书
  • 使用实验性 CUIcflags编译 node.js
  • 编译的 curl 支持 http3

我用 example 的内容创建了一个脚本:

'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!');
})();

对于 future 的读者来说,函数 getTLSKeySomehow()getTLSCertSomehow() 可以替换为:

const fs = require("fs")
const key = fs.readFileSync('privkey.pem')
const cert = fs.readFileSync('cert.pem')

然后我尝试通过在 Firefox 中启用 http3 并在 about:config 中启用功能标志 network.http.http3.enabled 来打开网页。使用地址 https://my.dev.domain.name:1234/ 但这没有用。

使用 curl 无效,可能值得注意的是我在 Windows 10 上使用 WSL。在 curl 上访问相同的 url 每次都会超时。只是为了检查我的设置是否正常:我可以验证 Firefox 和 curl 是否可以访问 www.google.com通过 http3 完美无缺。

当我使用相同的 key 实现第二个 http2 端点时,它工作正常,没有任何证书警告。

如何调试我做错的事情?

最佳答案

您的代码示例仅实现了 QUIC - 这是 HTTP/3 下的传输协议(protocol)(类似于 TCP + TLS 是 HTTP/1.1 下的传输协议(protocol))。

这意味着您需要额外的代码来在 Quic 之上实现 HTTP/3。理想情况下,您需要一个库,因为它相当复杂。以下是需要实现的最新规范草案版本的链接:

我假设 node.js 最终也会添加对这些的支持,这样这项任务就会变得更容易。

如果没有 HTTP/3 支持,您可以针对您的测试服务器测试纯 QUIC 流(没有 HTTP 语义)。您可以使用各种 QUIC 库中的任何一个来执行此操作,但可能没有像 curl 这样的开箱即用的 CLI 工具。

关于javascript - 调试 http3 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65531418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com