Skip to content

Commit ec70d32

Browse files
author
deiu
committed
Added real content negotiation
1 parent fa62f20 commit ec70d32

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎lib/handlers/get.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ var subscription = require('../subscription.js');
2020
var ldpVocab = require('../vocab/ldp.js');
2121
var turtleExtension = '.ttl';
2222

23+
// this should be moved to options
24+
var browseSkin = 'https://linkeddata.github.io/warp/#/list/';
25+
2326
function get(req, res, includeBody) {
2427
var ldp = req.app.locals.ldp;
2528
var uri = utils.uriBase(req);
@@ -32,6 +35,9 @@ function get(req, res, includeBody) {
3235
return subscription.subscribeToChanges(req, res);
3336
}
3437

38+
// Parse accept mime types into a priority (q) ordered array
39+
res.acceptTypes = header.negotiateContentType(req) || 'text/turtle';
40+
3541
// Set headers
3642
res.header('MS-Author-Via', 'SPARQL');
3743

@@ -109,6 +115,11 @@ function get(req, res, includeBody) {
109115
}
110116
}
111117

118+
// redirect to file browser if we got text/html with highest priority
119+
if (res.acceptTypes.indexOf('text/html') === 0) {
120+
return res.redirect(303, browseSkin + req.protocol + '/' + req.get('host') + req.path);
121+
}
122+
112123
// TODO this should be added as a middleware in the routes
113124
res.locals.turtleData = data;
114125
return parseLinkedData(req, res);
@@ -190,7 +201,7 @@ function parseLinkedData(req, res) {
190201
var uri = utils.uriBase(req);
191202
var turtleData = res.locals.turtleData;
192203

193-
var accept = header.parseAcceptHeader(req) || 'text/turtle';
204+
var accept = header.parseAcceptRDFHeader(req) || 'text/turtle';
194205
var baseUri = utils.filenameToBaseUri(filename, uri, ldp.root);
195206

196207
// Handle Turtle Accept header
@@ -228,7 +239,6 @@ function parseLinkedData(req, res) {
228239
});
229240
}
230241

231-
232242
function getHandler(req, res) {
233243
get(req, res, true);
234244
}

0 commit comments

Comments
 (0)