I have implemented simple proxy server with using node js. So the proxy will send Early hints response once it receives the request, it works well for HTTP/1.1 request but when I try with HTTP/2 request, it doesn't send the Early hints. I need to handle HTTP/2 Early hints because most of browsers are only accepting HTTP/2 or over Early Hints, not HTTP/1.1 Early hints. Please help me with how to fix this issue.
const http2 = require("http2");
const fs = require("fs");
const proxy = require("http2-proxy");
const options = {
key: fs.readFileSync("./key.pem"),
cert: fs.readFileSync("./cert.pem"),
passphrase: "password",
allowHTTP1: true,
};
const server = http2.createSecureServer(options, (req, res) => {
console.log("Hello", req.httpVersion);
res.writeEarlyHints(
{
link: ["</_next/static/css/11031e50f5a9bdb7.css>; rel=preload; as=style"],
},
() => {
console.log("Early Hints sent");
}
);
proxy.web(req, res, {
hostname: "mantine.dev",
protocol: "https",
});
});
server.listen(5000);
I tried to log for early hints and noticed that the callback function of writeEarlyHints is not executing in case of only HTTP/2 request.