From 9e16f5372cbc4a774ce04db957f8f5b2ca8a4944 Mon Sep 17 00:00:00 2001 From: Glen Arrowsmith Date: Fri, 3 Jul 2015 17:28:27 +1000 Subject: [PATCH 1/2] Fixes missing mimetype on cached files --- src/index.js | 14 ++++++++++++++ test/index.js | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/index.js b/src/index.js index f72708c..305489a 100644 --- a/src/index.js +++ b/src/index.js @@ -73,10 +73,24 @@ module.exports = function (_config) { } catch(e) {}; if(stat && now - createdAt < config.ttl) { + gm(config.cacheFolder + '/' + image.hash) .options(gmOptions) + .format({ + bufferStream: true + }, function (_error, _format) { + if(_error) { + console.log(_error); + return _callback(_error); + } + image.format = _format; + _res.set({ + 'Content-Type': 'image/' + _format.toLowerCase() + }); + }) .stream() .pipe(_res); + } else { _callback(); } diff --git a/test/index.js b/test/index.js index 04de802..ab76676 100644 --- a/test/index.js +++ b/test/index.js @@ -357,7 +357,24 @@ describe('immp', function () { }); + }); + + it('should still have the right content-type & size when cached', function (_done) { + http.get('http://localhost:3000/im/?image=/images/Landscape_8.jpg&quality=50', function (_httpResponse) { + + _httpResponse.headers['content-type'].should.eql('image/jpeg'); + + gm(_httpResponse) + .options(gmOptions) + .size(function (_error, _size) { + if(_error) return _done(_error); + _size.width.should.equal(600); + _size.height.should.equal(450); + _done(); + }); + + }); }); From 182bf4f5611456fd0d705e2534987e0c545ba702 Mon Sep 17 00:00:00 2001 From: Glen Arrowsmith Date: Fri, 3 Jul 2015 17:28:34 +1000 Subject: [PATCH 2/2] 1.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a0298c..d8ec1ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "immp", "description": "Image Manipulation Middleware Proxy", - "version": "1.2.1", + "version": "1.2.2", "repository": "garrows/IMMP", "keywords": [ "imageMagick",