Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ function handler (req, res, next) {
var ldp = req.app.locals.ldp
var includeBody = req.method === 'GET'
var negotiator = new Negotiator(req)
var requestedType = negotiator.mediaType()
var possibleRDFType = negotiator.mediaType(RDFs)
var baseUri = utils.uriBase(req)
var path = res.locals.path || req.path
var requestedType = negotiator.mediaType()
var possibleRDFType = negotiator.mediaType(RDFs)
// Fallback to text/turtle if content type is unknown
possibleRDFType = (!possibleRDFType) ? 'text/turtle' : possibleRDFType

res.header('MS-Author-Via', 'SPARQL')

Expand Down Expand Up @@ -65,11 +67,14 @@ function handler (req, res, next) {
}

// Handle defaultApp
if (container &&
requestedType.indexOf('text/html') === 0 &&
ldp.defaultApp) {
var address = req.protocol + '/' + req.get('host') + req.originalUrl
return res.redirect(303, ldp.defaultApp + address)
if (requestedType.indexOf('text/html') === 0) {
if (container && ldp.defaultApp) {
var address = req.protocol + '/' + req.get('host') + req.originalUrl
return res.redirect(303, ldp.defaultApp + address)
}
// Serve (pipe) resource as requested
res.setHeader('Content-Type', contentType)
return stream.pipe(res)
}

// If request accepts the content-type we found
Expand All @@ -82,7 +87,7 @@ function handler (req, res, next) {
// If it is not in our RDFs we can't even translate,
// Sorry, we can't help
if (!possibleRDFType) {
return next(error(406, 'Cannot server your type'))
return next(error(406, 'Cannot serve requested type: ' + contentType))
}

// Translate from the contentType found to the possibleRDFType desired
Expand Down
5 changes: 4 additions & 1 deletion lib/handlers/try-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ function handler (req, res, next) {
debug('looking for ' + res.locals.path)
// Check if file exists in first place
ldp.exists(req.hostname, res.locals.path, function (err) {
if (err) return next()
if (err) {
res.locals.path = res.path
return next()
}
debug('found an index for current path')
// Since it exists, can the user read this?
acl.allow('Read')(req, res, function (err) {
Expand Down
12 changes: 12 additions & 0 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ describe('HTTP APIs', function () {
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Container>; rel="type"/)
.expect(200, done)
})
it('should serve the right content type if requested as text/html', function (done) {
server.get('/sampleContainer/example1.ttl')
.set('Accept', 'text/html')
.expect('content-type', /text\/turtle/)
.expect(200, done)
})
it('should redirect to defaultApp if container was requested as text/html', function (done) {
server.get('/sampleContainer/')
.set('Accept', 'text/html')
.expect('content-type', /text\/html/)
.expect(200, done) // Can't check for 303 because of internal redirects
})
it('should return 404 for non-existent resource', function (done) {
server.get('/invalidfile.foo')
.expect(404, done)
Expand Down