We noticed that got
returned the wrong response for every second request, when making requests with enabled caching.
Apparently, when making requests with the cache
option, got
does not decode the cached response properly (based on the Content-Encoding
header of the cached response), but instead uses the Content-Encoding
-header of the 304 Not Modified response.
got
should be able to cache and re-use cached response, even if the 304 response is sent with a different Content-Encoding
header.
import http from 'node:http';
import zlib from 'node:zlib';
import got from 'got';
const gzipData = zlib.gzipSync('test');
const etag = '"asdf"';
const server = http
.createServer((req, res) => {
if (req.headers['if-none-match'] === etag) {
res.writeHead(304); // not, no Content-Encoding header
res.end();
return;
}
res.writeHead(200, { 'content-encoding': 'gzip', etag });
res.write(gzipData);
res.end();
})
.listen(2345);
const map = new Map();
for (let i = 0; i < 4; i++) {
const result = await got.get({
url: 'http://localhost:2345',
cache: map,
responseType: 'text',
});
console.log("response", i, result.body.slice(0, 32));
}
server.close();
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too