diff --git a/index.js b/index.js index 3fc9db8..d966421 100644 --- a/index.js +++ b/index.js @@ -167,8 +167,12 @@ var Framer = module.exports = function Framer(opts) { } res.setHeader('Content-Type', s3res.headers['content-type']); + res.setHeader('transfer-encoding', 'chunked'); if (sizeOptions === 'raw') { + if (s3res.headers['content-length']) { + res.setHeader('Content-Length', s3res.headers['content-length']); + } return s3res.pipe(res); } @@ -202,6 +206,9 @@ var Framer = module.exports = function Framer(opts) { }); res.setHeader('Content-Type', s3res.headers['content-type']); + if (s3res.headers['content-length']) { + res.setHeader('Content-Length', s3res.headers['content-length']); + } return s3res.pipe(res); }) diff --git a/test/test.file-download.js b/test/test.file-download.js index 83411cb..a9c09fa 100644 --- a/test/test.file-download.js +++ b/test/test.file-download.js @@ -14,9 +14,9 @@ describe('test image downloads', function () { var s3Options = { secure: false, - key: 'bogus', - secret: 'bogus', - bucket: 'bogus' + key: process.env.S3KEY || 'bogus', + secret: process.env.S3SECRET || 'bogus', + bucket: process.env.S3BUCKET || 'bogus' }; var s3Client = { @@ -27,10 +27,12 @@ describe('test image downloads', function () { mock.on = function (evt, cb) { if (evt === 'response') { if (imagePath === expectedPath) { + var len = fs.statSync(path.join(__dirname, 'file.txt')).size; var obj = fs.createReadStream(path.join(__dirname, 'file.txt')); obj.statusCode = 200; obj.headers = {}; obj.headers['content-type'] = 'text/html'; + obj.headers['content-length'] = len; cb(obj); } else { @@ -53,7 +55,7 @@ describe('test image downloads', function () { var serveFile = framer.serveFile({ prefix: '/file', cacheMaxAge: maxAge }); var client = http.createServer(function (req, res) { serveFile(req, res); - }).listen(PORT); + }); before(function (done) { client.listen(PORT, done); diff --git a/test/test.image-download.js b/test/test.image-download.js index f3ff37f..b781ba8 100644 --- a/test/test.image-download.js +++ b/test/test.image-download.js @@ -29,10 +29,12 @@ describe('test image downloads', function () { mock.on = function (evt, cb) { if (evt === 'response') { if (imagePath === expectedPath) { + var len = fs.statSync(path.join(__dirname, 'file.txt')).size; var obj = fs.createReadStream(path.join(__dirname, 'image.jpg')); obj.statusCode = 200; obj.headers = {}; obj.headers['content-type'] = 'image/jpeg'; + obj.headers['content-length'] = len; cb(obj); } else { @@ -71,6 +73,7 @@ describe('test image downloads', function () { assert.equal(200, res.statusCode); assert.equal(expectedFile.toString(), body.toString()); assert.equal('image/jpeg', res.headers['content-type']); + assert.ok(res.headers['content-length']); done(); }); }); @@ -109,6 +112,7 @@ describe('test image downloads', function () { assert.equal(200, res.statusCode); assert(expectedFile.equals(body)); assert.equal('image/jpeg', res.headers['content-type']); + assert.equal('chunked', res.headers['transfer-encoding']); done(); }); }); @@ -127,6 +131,7 @@ describe('test image downloads', function () { assert.equal(200, res.statusCode); assert(expectedFile.equals(body)); assert.equal('image/jpeg', res.headers['content-type']); + assert.equal('chunked', res.headers['transfer-encoding']); done(); }); }); @@ -140,6 +145,7 @@ describe('test image downloads', function () { assert.equal(200, res.statusCode); assert.equal('public, max-age=' + maxAge, res.headers['cache-control']); assert.equal('image/jpeg', res.headers['content-type']); + assert.equal('chunked', res.headers['transfer-encoding']); done(); }); });