diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/serve.js b/lib/serve.js index 7c4350b..7cda95d 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -15,6 +15,8 @@ var ssbMentions = require('ssb-mentions') var multicb = require('multicb') var pkg = require('../package') var Busboy = require('busboy') +var mime = require('mime-types') +var ident = require('pull-identify-filetype') module.exports = Serve @@ -128,7 +130,7 @@ Serve.prototype.respond = function (status, message) { Serve.prototype.respondSink = function (status, headers, cb) { var self = this - self.res.writeHead(status, headers) + if (status && headers) self.res.writeHead(status, headers) return toPull(self.res, cb || function (err) { if (err) self.error(err) }) @@ -486,15 +488,19 @@ Serve.prototype.blob = function (id) { else return self.respond(500, err.message || err) } if (!has) return self.respond(404, 'Not found') - if (self.query.name) self.res.setHeader('Content-Disposition', - 'inline; filename='+encodeURIComponent(self.query.name)) pull( blobs.get(id), pull.map(Buffer), - self.respondSink(200, { - 'Cache-Control': 'public, max-age=315360000', - 'etag': id - }) + ident(function (type) { + type = type && mime.lookup(type) + if (type) self.res.setHeader('Content-Type', type) + if (self.query.name) self.res.setHeader('Content-Disposition', + 'inline; filename='+encodeURIComponent(self.query.name)) + self.res.setHeader('Cache-Control', 'public, max-age=315360000') + self.res.setHeader('etag', id) + self.res.writeHead(200) + }), + self.respondSink() ) }) } |