Last active
September 19, 2017 22:06
-
-
Save ShakataGaNai/94fbac3e5a24eca6eedc4acd2d877cc7 to your computer and use it in GitHub Desktop.
A quick demonstration of using Lamba@Edge to inject extra HTTP Security/Cache Headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
exports.handler = (event, context, callback) => { | |
const response = event.Records[0].cf.response; | |
const headers = response.headers; | |
var hr = { | |
'Strict-Transport-Security': 'max-age=600;', | |
'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', | |
'Pragma': 'no-cache', | |
'X-LambdaAtEdge': 'true' | |
}; | |
for (var key in hr){ | |
headers[key.toLowerCase()] = [ | |
{ key: key, value: hr[key]} | |
]; | |
} | |
callback(null, response); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment