I have a very tentative understanding of headers, caching and curls in general, let alone Cloudfront/S3 and what those're doing — so, sorry if this ends up not making any sense at all.
Currently, we have a Lambda Edge script with an originResponse for setting cache-control max-age values. It uses a switch with cases for content-type to assign different values based on that, and defaults if all cases miss.
When I try a curl -I
on content, it'll return with the expected max-age, but using curl -I --compressed
or just inspecting from a browser shows everything setting to the switch's default value instead.
I think I understand that it's related to compression, but that's as far as I am and I'm entirely lost on how to address this otherwise.
Request headers have accept-encoding: gzip, ...
, but none of the content has a response header of content-encoding: gzip
. I don't know if Cloudfront would automatically set that header itself if it's appropriate — and if so, could content still be "compressed" in another format besides gzip? Would missing a content-encoding
header cause oddness? Is this even related to my issue?
Right about now, I want to apologise again for how little sense this question could be making, there're a few layers to how the site works, plus I'm unsure of where the line is with NDA on top of my own confusion.
The title's really my question put brief. I'm trying to figure out how to make curl calls of --compressed
show the same max-age as without.
Edit: There's also currently an issue of S3(?) assigning MIME content-types of binary/octet-stream
to things like .woff2 fonts that I'm working on as well. I can't tell how related these issues are, and if maybe reassigned types or object restructuring (if that's a thing?) are causing the switch fails. But that said, the content-types in the original question are showing what's expected, so I have no idea why it's hitting the default.
if (headers['content-type'] && undefined === headers['cache-control']) {
switch (headers['content-type'][0].value) {
case 'image/jpg':
setHeader('Cache-Control', 'public, max-age=2592000') // ← "curl -I" shows this
break
...
default:
setHeader('Cache-Control', 'public, max-age=3600') // ← "curl -I --compressed" shows this
break
Edit 2: I originally posted this question over on reddit for a bit more context in the comments.