Skip to content

Commit 1d5ecbc

Browse files
authored
Merge pull request #831 from solid/feature/454
Setting contentType for HEAD requests
2 parents f276c57 + c13f971 commit 1d5ecbc

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

lib/handlers/get.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const translate = require('../utils.js').translate
1717
const error = require('../http-error')
1818

1919
const RDFs = require('../ldp').RDF_MIME_TYPES
20+
const LegacyResourceMapper = require('../legacy-resource-mapper')
2021

2122
function handler (req, res, next) {
2223
const ldp = req.app.locals.ldp
@@ -76,8 +77,18 @@ function handler (req, res, next) {
7677
// Till here it must exist
7778
if (!includeBody) {
7879
debug('HEAD only')
79-
res.sendStatus(200)
80-
return next()
80+
const rootUrl = utils.getBaseUri(req)
81+
const mapper = new LegacyResourceMapper({
82+
rootUrl,
83+
rootPath: ldp.root,
84+
includeHost: ldp.multiuser
85+
})
86+
return mapper.mapFileToUrl({ path }).then(mappedFile => {
87+
contentType = mappedFile.contentType
88+
res.setHeader('Content-Type', contentType)
89+
res.status(200).send('OK')
90+
return next()
91+
})
8192
}
8293

8394
// Handle dataBrowser

test/integration/http-test.js

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

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

test/integration/ldp-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('LDP', function () {
250250
if (err) done(err)
251251
fs.readdir(path.join(__dirname, '../resources/sampleContainer/'), function (err, expectedFiles) {
252252
const graph = $rdf.graph()
253-
$rdf.parse(data, graph, 'https://server.tld/sampleContainer', 'text/turtle')
253+
$rdf.parse(data, graph, 'https://server.tld/sampleContainer/', 'text/turtle')
254254
const statements = graph.match(null, ns.ldp('contains'), null)
255255
const files = statements
256256
.map(s => s.object.value.replace(/.*\//, ''))

test/resources/sampleContainer/blank

Whitespace-only changes.

0 commit comments

Comments
 (0)