Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HTTP 404 & forward Cache-Control, Content-Type, Expires, and Last-Modified headers from S3. #158

Closed
wants to merge 9 commits into from

Conversation

john-shaffer
Copy link

@john-shaffer john-shaffer commented Oct 23, 2019

Fixes #159, #103, and #120.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@john-shaffer john-shaffer changed the title Forward Expires and Last-Modified headers from S3. Forward Content-Type, Expires, and Last-Modified headers from S3. Oct 23, 2019
@john-shaffer john-shaffer changed the title Forward Content-Type, Expires, and Last-Modified headers from S3. Use HTTP 404 & forward Content-Type, Expires, and Last-Modified headers from S3. Oct 25, 2019
@@ -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.

@beomseoklee
Copy link
Member

Thanks for your input. We will consider to change in the next release.

@bretto36
Copy link

@beomseoklee - How often are releases performed? I'd love to incorporate this change into our platform

@vitalinfo
Copy link

vitalinfo commented Dec 19, 2019

@beomseoklee any news about this PR? because next release was a few days ago since your last message

@vitalinfo
Copy link

@john-shaffer I think will be great to have original Cache-Control as well in this PR as well
like master...vitalinfo:master
Thanks

p.s. also need fix tests according to these changes

@vitalinfo
Copy link

vitalinfo commented Dec 20, 2019

@john-shaffer btw, please take a look changes in my fork, need to add conditions to the dates, if original object doesn't have such headers, client will receive Invalid Date

@john-shaffer
Copy link
Author

@vitalinfo I merged your changes and added similar conditions on the other headers so that the tests all pass.

@john-shaffer john-shaffer changed the title Use HTTP 404 & forward Content-Type, Expires, and Last-Modified headers from S3. Use HTTP 404 & forward Cache-Control, Content-Type, Expires, and Last-Modified headers from S3. Dec 20, 2019
Susan123456789 added a commit to Susan123456789/serverless-image-handler that referenced this pull request Feb 3, 2020
@@ -22,9 +22,14 @@ exports.handler = async (event) => {
const request = await imageRequest.setup(event);
console.log(request);
const processedRequest = await imageHandler.process(request);
const headers = getResponseHeaders();
headers["Content-Type"] = request.ContentType;
Copy link

Choose a reason for hiding this comment

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

What if you are changing the image from a jpg to a png.

If i put
'toFormat' => 'png'
in my image settings but the source is a jpeg this will output image/jpg

headers["Content-Type"] = request.ContentType;
headers["Expires"] = request.Expires;
headers["Last-Modified"] = request.LastModified;
headers["Cache-Control"] = request.CacheControl;
Copy link

Choose a reason for hiding this comment

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

Would it be possible to supply overridden values? In the base64 encoded string
{
"header": [{'Expires' : x }]
}

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, @bretto36. I'm not using either of those features (changing formats or base64), but I'll take a look when I get a chance.

@beomseoklee
Copy link
Member

Thanks for your effort here, @john-shaffer
We have updated our solution, and your pull request has been merged into our master branch. However, as we've merged many pull requests at this time, the source code might not exactly same as what you've done. In addition, due to our internal process, we've merged source code manually, so please understand how your effort has been merged.

You can refer to the recent changes here

@john-shaffer
Copy link
Author

Thank you, @beomseoklee. We're very happy with the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use HTTP 404 status for missing images
6 participants