Skip to content
4 changes: 3 additions & 1 deletion source/image-handler/image-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ImageRequest {
const request = s3.getObject(imageLocation).promise();
try {
const originalImage = await request;
this.Expires = originalImage.Expires;
this.LastModified = originalImage.LastModified;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this fix and the s3.getObject() call returns an invalid date format (e.g. 2019-11-06T21:36:00.000z). Added the following to change into a valid HTTP header format.

const formattedLastModified = new Date(originalImage.LastModified).toUTCString();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I noticed this, but hadn't had time to investigate it. That fix is in the pull request now.

return Promise.resolve(originalImage.Body);
}
catch(err) {
Expand Down Expand Up @@ -235,4 +237,4 @@ class ImageRequest {
}

// Exports
module.exports = ImageRequest;
module.exports = ImageRequest;
7 changes: 5 additions & 2 deletions source/image-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ exports.handler = async (event) => {
const request = await imageRequest.setup(event);
console.log(request);
const processedRequest = await imageHandler.process(request);
const headers = getResponseHeaders();
headers["Expires"] = request.Expires;
headers["Last-Modified"] = request.LastModified;
const response = {
"statusCode": 200,
"headers" : getResponseHeaders(),
"headers" : headers,
"body": processedRequest,
"isBase64Encoded": true
}
Expand Down Expand Up @@ -61,4 +64,4 @@ const getResponseHeaders = (isErr) => {
headers["Content-Type"] = "application/json"
}
return headers;
}
}