I'm trying to setup an testing environment for http3 just for learning.
What I did so far:
I created a script with the content of the 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!');
})();
Just for future readers the functions getTLSKeySomehow() and getTLSCertSomehow() can be replaced by this:
const fs = require("fs")
const key = fs.readFileSync('privkey.pem')
const cert = fs.readFileSync('cert.pem')
Then I tried to open the webpage by enableding http3 in Firefox with the feature-flag network.http.http3.enabled enabled in about:config. With the address https://my.dev.domain.name:1234/ but this didn't work.
Using curl didn't work ether, might be worth noting that I'm using WSL on Windows 10. Accessing the same url on curl times out everytime. Just to check that my setup is fine: I can verify that Firefox and curl can access www.google.com flawless via http3.
When I implement a second http2 endpoint with the same key this works fine without any certificate warnings.
How can I debug what I'm doing wrong?
Your code sample just implements QUIC - which is the transport protocol underneath HTTP/3 (similar to how TCP + TLS are the transport protocols below HTTP/1.1).
This means you need additional code for implementing HTTP/3 on top of Quic. Ideally you want a library, since it's rather complex. Here are links to the most recent draft version of the specifications which need to be implemented:
I assume node.js would eventually also add support for those, so that this task gets easier.
Without HTTP/3 support, you could test pure QUIC streams (without HTTP semantics) against your test server. You can use any of the various QUIC libraries to do this, but there might not be an out of the box CLI tool like curl.