Skip to content

Instantly share code, notes, and snippets.

@matthewberryman
Created October 4, 2019 23:02
Show Gist options
  • Save matthewberryman/433530a9413441aaf0e3013926f06f23 to your computer and use it in GitHub Desktop.
Save matthewberryman/433530a9413441aaf0e3013926f06f23 to your computer and use it in GitHub Desktop.
vary_headers.js
'use strict';
// If the response lacks a Vary: header, fix it in a CloudFront Origin Response trigger.
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
const headers = response.headers;
if (!headers['vary'])
{
headers['vary'] = [
{ key: 'Vary', value: 'Access-Control-Request-Headers' },
{ key: 'Vary', value: 'Access-Control-Request-Method' },
{ key: 'Vary', value: 'Origin' },
];
}
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment