fix: Forward headers correctly when reading from S3

This commit is contained in:
Maksim Eltyshev
2026-02-04 11:34:47 +01:00
parent 3c33161df6
commit 8df5a111bf
2 changed files with 24 additions and 14 deletions

View File

@@ -51,15 +51,13 @@ class LocalFileManager {
const readStream = fs.createReadStream(filePath);
if (withHeaders) {
const weakEtag = `W/"${stat.size.toString(16)}-${stat.mtime.getTime().toString(16)}"`;
return [
readStream,
{
'Content-Type': mime.lookup(filePathSegment) || 'application/octet-stream',
'Content-Length': stat.size,
'Last-Modified': stat.mtime.toUTCString(),
ETag: weakEtag,
ETag: `W/"${stat.size.toString(16)}-${stat.mtime.getTime().toString(16)}"`,
'Accept-Ranges': 'bytes',
},
];

View File

@@ -56,17 +56,29 @@ class S3FileManager {
const result = await this.client.send(command);
if (withHeaders) {
return [
result.Body,
{
'Content-Type':
result.ContentType || mime.lookup(filePathSegment) || 'application/octet-stream',
'Content-Length': result.ContentLength,
'Last-Modified': result.LastModified && result.LastModified.toUTCString(),
ETag: result.ETag,
'Accept-Ranges': result.AcceptRanges || 'bytes',
},
];
const headers = {
'Content-Type':
result.ContentType || mime.lookup(filePathSegment) || 'application/octet-stream',
'Accept-Ranges': result.AcceptRanges || 'bytes',
};
if (!_.isUndefined(result.ContentLength)) {
headers['Content-Length'] = result.ContentLength;
}
if (!_.isUndefined(result.LastModified)) {
headers['Last-Modified'] = result.LastModified.toUTCString();
}
if (_.isUndefined(result.ETag)) {
if (!_.isUndefined(result.ContentLength) && !_.isUndefined(result.LastModified)) {
headers.ETag = `W/"${result.ContentLength.toString(16)}-${result.LastModified.getTime().toString(16)}"`;
}
} else {
headers.ETag = result.ETag;
}
return [result.Body, headers];
}
return result.Body;