Skip to content

Commit

Permalink
Merge pull request #3 from garrows/fix/cached-mimetype
Browse files Browse the repository at this point in the history
Fix/cached mimetype
  • Loading branch information
garrows committed Jul 3, 2015
2 parents 698ba1b + 182bf4f commit 0f066f8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "immp",
"description": "Image Manipulation Middleware Proxy",
"version": "1.2.1",
"version": "1.2.2",
"repository": "garrows/IMMP",
"keywords": [
"imageMagick",
Expand Down
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
17 changes: 17 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

});

});

Expand Down

0 comments on commit 0f066f8

Please sign in to comment.