Skip to content

Commit 55e3ff6

Browse files
committed
Setting contentType for HEAD requests
1 parent 7cd9106 commit 55e3ff6

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

lib/handlers/get.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ function handler (req, res, next) {
7676
// Till here it must exist
7777
if (!includeBody) {
7878
debug('HEAD only')
79-
res.sendStatus(200)
79+
contentType = mime.contentType(_path.extname(path))
80+
res.setHeader('Content-Type', contentType)
81+
res.status(200).send('OK')
8082
return next()
8183
}
8284

@@ -85,8 +87,8 @@ function handler (req, res, next) {
8587
let mimeTypeByExt = mime.lookup(_path.basename(path))
8688
let isHtmlResource = mimeTypeByExt && mimeTypeByExt.includes('html')
8789
let useDataBrowser = ldp.dataBrowserPath && (
88-
container ||
89-
RDFs.includes(contentType) && !isHtmlResource && !ldp.suppressDataBrowser)
90+
container ||
91+
RDFs.includes(contentType) && !isHtmlResource && !ldp.suppressDataBrowser)
9092

9193
if (useDataBrowser) {
9294
res.set('Content-Type', 'text/html')
@@ -160,7 +162,7 @@ function globHandler (req, res, next) {
160162
debugGlob('found matches ' + matches)
161163
Promise.all(matches.map(match => new Promise((resolve, reject) => {
162164
const baseUri = reqOrigin + '/' + match.substr(root.length)
163-
fs.readFile(match, {encoding: 'utf8'}, function (err, fileData) {
165+
fs.readFile(match, { encoding: 'utf8' }, function (err, fileData) {
164166
if (err) {
165167
debugGlob('error ' + err)
166168
return resolve()
@@ -182,15 +184,15 @@ function globHandler (req, res, next) {
182184
})
183185
})
184186
})))
185-
.then(() => {
186-
const data = $rdf.serialize(undefined, globGraph, requestUri, 'text/turtle')
187-
// TODO this should be added as a middleware in the routes
188-
res.setHeader('Content-Type', 'text/turtle')
189-
debugGlob('returning turtle')
190-
191-
res.send(data)
192-
return next()
193-
})
187+
.then(() => {
188+
const data = $rdf.serialize(undefined, globGraph, requestUri, 'text/turtle')
189+
// TODO this should be added as a middleware in the routes
190+
res.setHeader('Content-Type', 'text/turtle')
191+
debugGlob('returning turtle')
192+
193+
res.send(data)
194+
return next()
195+
})
194196
})
195197
}
196198

test/integration/http-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ describe('HTTP APIs', function () {
368368
})
369369

370370
describe('HEAD API', function () {
371+
it('should have set content-type for turtle files',
372+
function (done) {
373+
server.head('/sampleContainer/example1.ttl')
374+
.expect('Content-Type', 'text/turtle; charset=utf-8')
375+
.end(done)
376+
})
377+
it('should have set content-type for image files',
378+
function (done) {
379+
server.head('/sampleContainer/solid.png')
380+
.expect('Content-Type', 'image/png; charset=utf-8')
381+
.end(done)
382+
})
371383
it('should have Access-Control-Allow-Origin as Origin', function (done) {
372384
server.head('/sampleContainer/example1.ttl')
373385
.set('Origin', 'http://example.com')

0 commit comments

Comments
 (0)