aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-03-05 16:26:33 -0500
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-03-05 16:26:33 -0500
commit0a5bea5a927ac8a3998f5b1659e9fa8d3c8f2a6c (patch)
tree1f43d944ba3226204d5c390cfa5fa7744a0891ce /lib
parent1168e132e90f0653700134b7a7f0b81edfaead8e (diff)
downloadpatchfoo-0a5bea5a927ac8a3998f5b1659e9fa8d3c8f2a6c.tar.gz
patchfoo-0a5bea5a927ac8a3998f5b1659e9fa8d3c8f2a6c.zip
Set content-type when serving blobs
Diffstat (limited to 'lib')
-rw-r--r--lib/serve.js20
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()
)
})
}