fix: Forward headers correctly when reading from S3
This commit is contained in:
@@ -51,15 +51,13 @@ class LocalFileManager {
|
|||||||
const readStream = fs.createReadStream(filePath);
|
const readStream = fs.createReadStream(filePath);
|
||||||
|
|
||||||
if (withHeaders) {
|
if (withHeaders) {
|
||||||
const weakEtag = `W/"${stat.size.toString(16)}-${stat.mtime.getTime().toString(16)}"`;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
readStream,
|
readStream,
|
||||||
{
|
{
|
||||||
'Content-Type': mime.lookup(filePathSegment) || 'application/octet-stream',
|
'Content-Type': mime.lookup(filePathSegment) || 'application/octet-stream',
|
||||||
'Content-Length': stat.size,
|
'Content-Length': stat.size,
|
||||||
'Last-Modified': stat.mtime.toUTCString(),
|
'Last-Modified': stat.mtime.toUTCString(),
|
||||||
ETag: weakEtag,
|
ETag: `W/"${stat.size.toString(16)}-${stat.mtime.getTime().toString(16)}"`,
|
||||||
'Accept-Ranges': 'bytes',
|
'Accept-Ranges': 'bytes',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -56,17 +56,29 @@ class S3FileManager {
|
|||||||
const result = await this.client.send(command);
|
const result = await this.client.send(command);
|
||||||
|
|
||||||
if (withHeaders) {
|
if (withHeaders) {
|
||||||
return [
|
const headers = {
|
||||||
result.Body,
|
|
||||||
{
|
|
||||||
'Content-Type':
|
'Content-Type':
|
||||||
result.ContentType || mime.lookup(filePathSegment) || 'application/octet-stream',
|
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',
|
'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;
|
return result.Body;
|
||||||
|
|||||||
Reference in New Issue
Block a user