首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调试http3设置

调试http3设置
EN

Stack Overflow用户
提问于 2021-01-01 16:19:23
回答 1查看 1.1K关注 0票数 3

我试图为http3设置一个测试环境,以便学习。

我到目前为止所做的:

  • 我们用dns-01加密证书
  • 用实验CUIC标志编译node.js
  • 使用http3支持编译的curl

我创建了一个包含示例内容的脚本

代码语言:javascript
复制
'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()函数可以被以下内容所取代:

代码语言:javascript
复制
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端点时,没有任何证书警告,这很好。

我如何调试我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 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工具。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65531418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档