Concurrent requests to subdomains resolving to the same IP address, e.g.
return the same response for all requests.
The problem only occurs when using HTTP/2.
To reproduce:
const crypto = require('crypto');
const { fetch } = require('fetch-h2');
async function request(url) {
const res = await fetch(url);
const data = await res.text();
const md5 = crypto.createHash('md5').update(data).digest().toString('hex');
console.log(`HTTP Version: ${res.httpVersion}, hash of ${url} response: ${md5}`);
}
async function run() {
await Promise.all([
request('https://already--grantila.hlx.page/README.html'),
request('https://fetch-h2--grantila.hlx.page/README.html'),
]);
}
run().catch(console.error);
Running the above code will output identical md5 hash values for both responses.
Workarounds:
- force
HTTP1(.1) protocol:
const { fetch } = require('fetch-h2').context({ httpsProtocols: ['http1'] });
- explicitly set
Host header:
const res = await fetch(url, {
headers: {
host: new URL(url).host,
},
allowForbiddenHeaders: true,
});