Skip to content

Instantly share code, notes, and snippets.

@furkan3ayraktar
Created March 29, 2018 15:40
Show Gist options
  • Save furkan3ayraktar/d0c2d0d39d0f62e17811b1e881c0e65e to your computer and use it in GitHub Desktop.
Save furkan3ayraktar/d0c2d0d39d0f62e17811b1e881c0e65e to your computer and use it in GitHub Desktop.
Content downloader used in Lambda@Edge function.
const https = require('https');
const zlib = require('zlib');
const downloadContent = (url, callback) => {
https.get(url, (res) => {
let response;
let body = '';
if (res.headers['content-encoding'] === 'gzip') {
response = res.pipe(zlib.createGunzip());
} else {
response = res;
}
response.on('data', (chunk) => {
body += chunk;
});
response.on('end', () => {
callback(true, body, res.headers);
});
}).on('error', (e) => callback(false, e));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment