Skip to content

Commit fbd30b0

Browse files
committed
text/turtle defaultContainerContentType
1 parent 33f7354 commit fbd30b0

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

lib/ldp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ class LDP {
470470
throw err
471471
}
472472
const stream = stringToStream(data)
473-
// TODO 'text/turtle' is fixed, should be contentType instead
474-
// This forces one more translation turtle -> desired
475-
return { stream, contentType: 'text/turtle', container: true }
473+
// TODO contentType is defaultContainerContentType ('text/turtle'),
474+
// This forces one translation turtle -> desired
475+
return { stream, contentType, container: true }
476476
} else {
477477
let chunksize, contentRange, start, end
478478
if (options.range) {

lib/resource-mapper.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ResourceMapper {
2525
rootPath,
2626
includeHost = false,
2727
defaultContentType = 'application/octet-stream',
28+
defaultContainerContentType = 'text/turtle',
2829
indexFilename = 'index.html',
2930
overrideTypes = { acl: 'text/turtle', meta: 'text/turtle' }
3031
}) {
@@ -33,6 +34,7 @@ class ResourceMapper {
3334
this._includeHost = includeHost
3435
this._readdir = readdir
3536
this._defaultContentType = defaultContentType
37+
this._defaultContainerContentType = defaultContainerContentType
3638
this._types = { ...types, ...overrideTypes }
3739
this._indexFilename = indexFilename
3840
this._indexContentType = this._getContentTypeFromExtension(indexFilename)
@@ -187,10 +189,11 @@ class ResourceMapper {
187189
return url
188190
}
189191

190-
// Gets the expected content type based on the extension of the path
192+
// Gets the expected content type based on resource type and the extension of the path
191193
_getContentTypeFromExtension (path) {
194+
const defaultContentType = (path === '' || path.endsWith('/')) ? this._defaultContainerContentType : this._defaultContentType
192195
const extension = /\.([^/.]+)$/.exec(path)
193-
return extension && this._types[extension[1].toLowerCase()] || this._defaultContentType
196+
return extension && this._types[extension[1].toLowerCase()] || defaultContentType
194197
}
195198

196199
// Appends an extension for the specific content type, if needed

test/integration/http-test.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ describe('HTTP APIs', function () {
426426
.expect('Content-Type', 'application/octet-stream; charset=utf-8')
427427
.end(done)
428428
})
429+
it('should return content-type text/turtle for container', function (done) {
430+
server.head('/sampleContainer2/')
431+
.expect('Content-Type', 'text/turtle; charset=utf-8')
432+
.end(done)
433+
})
429434
it('should have set content-type for turtle files',
430435
function (done) {
431436
server.head('/sampleContainer2/example1.ttl')
@@ -456,7 +461,7 @@ describe('HTTP APIs', function () {
456461
.expect(200, done)
457462
})
458463
it('should have set Updates-Via to use WebSockets', function (done) {
459-
server.get('/sampleContainer2/example1.ttl')
464+
server.head('/sampleContainer2/example1.ttl')
460465
.expect('updates-via', /wss?:\/\//)
461466
.expect(200, done)
462467
})
@@ -467,21 +472,27 @@ describe('HTTP APIs', function () {
467472
})
468473
it('should have set acl and describedBy Links for resource',
469474
function (done) {
470-
server.get('/sampleContainer2/example1.ttl')
475+
server.head('/sampleContainer2/example1.ttl') // get
471476
.expect(hasHeader('acl', 'example1.ttl' + suffixAcl))
472477
.expect(hasHeader('describedBy', 'example1.ttl' + suffixMeta))
473478
.end(done)
474479
})
480+
it('should have set Content-Type as text/turtle for Container',
481+
function (done) {
482+
server.head('/sampleContainer2/')
483+
.expect('Content-Type', 'text/turtle; charset=utf-8')
484+
.expect(200, done)
485+
})
475486
it('should have set Link as Container/BasicContainer',
476487
function (done) {
477-
server.get('/sampleContainer2/')
488+
server.head('/sampleContainer2/')
478489
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#BasicContainer>; rel="type"/)
479490
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Container>; rel="type"/)
480491
.expect(200, done)
481492
})
482493
it('should have set acl and describedBy Links for container',
483494
function (done) {
484-
server.get('/sampleContainer2/')
495+
server.head('/sampleContainer2/')
485496
.expect(hasHeader('acl', suffixAcl))
486497
.expect(hasHeader('describedBy', suffixMeta))
487498
.end(done)

test/unit/resource-mapper-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ describe('ResourceMapper', () => {
282282
],
283283
{
284284
path: `${rootPath}space/`,
285-
contentType: 'application/octet-stream'
285+
contentType: 'text/turtle' // 'application/octet-stream'
286286
})
287287

288288
itMapsUrl(mapper, 'a URL ending with a slash when index$.html is available',
@@ -295,7 +295,7 @@ describe('ResourceMapper', () => {
295295
],
296296
{
297297
path: `${rootPath}space/`,
298-
contentType: 'application/octet-stream'
298+
contentType: 'text/turtle' // 'application/octet-stream'
299299
})
300300

301301
itMapsUrl(mapper, 'a URL ending with a slash when index$.ttl is available',
@@ -307,7 +307,7 @@ describe('ResourceMapper', () => {
307307
],
308308
{
309309
path: `${rootPath}space/`,
310-
contentType: 'application/octet-stream'
310+
contentType: 'text/turtle' // 'application/octet-stream'
311311
})
312312

313313
itMapsUrl(mapper, 'a URL ending with a slash to a folder when index.html is available but index is skipped',
@@ -321,7 +321,7 @@ describe('ResourceMapper', () => {
321321
],
322322
{
323323
path: `${rootPath}space/`,
324-
contentType: 'application/octet-stream'
324+
contentType: 'text/turtle' // 'application/octet-stream'
325325
})
326326

327327
itMapsUrl(mapper, 'a URL ending with a slash to a folder when no index is available',
@@ -330,7 +330,7 @@ describe('ResourceMapper', () => {
330330
},
331331
{
332332
path: `${rootPath}space/`,
333-
contentType: 'application/octet-stream'
333+
contentType: 'text/turtle' // 'application/octet-stream'
334334
})
335335

336336
itMapsUrl(mapper, 'a URL of that has an accompanying acl file, but no actual file',
@@ -342,7 +342,7 @@ describe('ResourceMapper', () => {
342342
],
343343
{
344344
path: `${rootPath}space/`,
345-
contentType: 'application/octet-stream'
345+
contentType: 'text/turtle' // 'application/octet-stream'
346346
})
347347

348348
itMapsUrl(mapper, 'a URL ending with a slash for text/html when index.html is not available',
@@ -373,13 +373,13 @@ describe('ResourceMapper', () => {
373373
itMapsUrl(mapper, 'a URL ending with a slash to a folder when index is skipped',
374374
{
375375
url: 'http://localhost/space/',
376-
contentType: 'application/octet-stream',
376+
contentType: 'text/turtle', // 'application/octet-stream',
377377
createIfNotExists: true,
378378
searchIndex: false
379379
},
380380
{
381381
path: `${rootPath}space/`,
382-
contentType: 'application/octet-stream'
382+
contentType: 'text/turtle' // 'application/octet-stream'
383383
})
384384

385385
itMapsUrl(mapper, 'a URL ending with a slash for text/turtle',

0 commit comments

Comments
 (0)